FIrst nonorganic posts
This commit is contained in:
@@ -48,6 +48,46 @@ userDB = (DB) => {
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.getPopularProfiles = async (limit = 10) => {
|
||||
return DB.profileCols.aggregate([
|
||||
{
|
||||
$match: {isGroup: false}
|
||||
},
|
||||
{
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ {"$objectToArray" : "$subscribed"}, [] ] } } }
|
||||
},
|
||||
{
|
||||
$sort: {"subscribed_count":-1}
|
||||
},
|
||||
{
|
||||
$project: {_id: 1, "subscribed_count": 1}
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPopularGroups = async (limit = 10) => {
|
||||
return DB.profileCols.aggregate([
|
||||
{
|
||||
$match: {isGroup: true, isPrivate: false, isCourse: false}
|
||||
},
|
||||
{
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ {"$objectToArray" : "$subscribed"}, [] ] } } }
|
||||
},
|
||||
{
|
||||
$sort: {"subscribed_count":-1}
|
||||
},
|
||||
{
|
||||
$project: {_id: 1, "subscribed_count": 1}
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getProfileCache = async (profileId) => {
|
||||
if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId];
|
||||
return DB.getProfile(profileId);
|
||||
|
||||
Reference in New Issue
Block a user