FIrst nonorganic posts

This commit is contained in:
aeroreyna
2022-02-16 22:28:11 -08:00
parent 117bc5833a
commit e0c6470bce
3 changed files with 57 additions and 2 deletions

View File

@@ -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);