initerest and random merge posts
This commit is contained in:
@@ -51,10 +51,10 @@ userDB = (DB) => {
|
||||
DB.getPopularProfiles = async (limit = 10) => {
|
||||
return DB.profileCols.aggregate([
|
||||
{
|
||||
$match: {isGroup: false}
|
||||
$match: {isGroup: {$ne: true}}
|
||||
},
|
||||
{
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ {"$objectToArray" : "$subscribed"}, [] ] } } }
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ "$following", [] ] } } }
|
||||
},
|
||||
{
|
||||
$sort: {"subscribed_count":-1}
|
||||
@@ -64,7 +64,7 @@ userDB = (DB) => {
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,7 +84,33 @@ userDB = (DB) => {
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
DB.getFriendsFriends = async (profileId) => {
|
||||
const profile = await DB.getProfile(profileId);
|
||||
if(!profile) return [];
|
||||
let ids = profile.following.map((id)=>DB.ObjectID(id));
|
||||
let alreadyFollowingMap = {};
|
||||
alreadyFollowingMap[profileId] = 1; //skip that profile
|
||||
profile.following.forEach(id => {
|
||||
if(!alreadyFollowingMap[id]) alreadyFollowingMap[id] = 1;
|
||||
})
|
||||
return DB.profileCols.find({_id:{$in: ids}}).project({following: 1}).toArray().then(profiles => {
|
||||
let friendsOfFriendsMap = {};
|
||||
profiles.forEach(p => {
|
||||
p.following.forEach(followingId => {
|
||||
if(alreadyFollowingMap[followingId]) return 0;
|
||||
if(!friendsOfFriendsMap[followingId]) friendsOfFriendsMap[followingId] = 0;
|
||||
friendsOfFriendsMap[followingId] = friendsOfFriendsMap[followingId] + 1;
|
||||
});
|
||||
});
|
||||
// sort by most related?
|
||||
return Object.keys(friendsOfFriendsMap);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user