mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
Merge branch 'develop' into activitypub
This commit is contained in:
@@ -45,7 +45,7 @@ module.exports = function (Topics) {
|
||||
let tids = [];
|
||||
if (params.term !== 'alltime') {
|
||||
if (params.sort === 'posts') {
|
||||
tids = await getTidsWithMostPostsInTerm(params.term);
|
||||
tids = await getTidsWithMostPostsInTerm(params.cids, params.uid, params.term);
|
||||
} else {
|
||||
tids = await Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term);
|
||||
}
|
||||
@@ -84,8 +84,20 @@ module.exports = function (Topics) {
|
||||
return 'topics:recent';
|
||||
}
|
||||
|
||||
async function getTidsWithMostPostsInTerm(term) {
|
||||
const pids = await db.getSortedSetRevRangeByScore('posts:pid', 0, -1, '+inf', Date.now() - Topics.getSinceFromTerm(term));
|
||||
async function getTidsWithMostPostsInTerm(cids, uid, term) {
|
||||
if (Array.isArray(cids)) {
|
||||
cids = await privileges.categories.filterCids('topics:read', cids, uid);
|
||||
} else {
|
||||
cids = await categories.getCidsByPrivilege('categories:cid', uid, 'topics:read');
|
||||
}
|
||||
|
||||
const pids = await db.getSortedSetRevRangeByScore(
|
||||
cids.map(cid => `cid:${cid}:pids`),
|
||||
0,
|
||||
1000,
|
||||
'+inf',
|
||||
Date.now() - Topics.getSinceFromTerm(term)
|
||||
);
|
||||
const postObjs = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['tid']);
|
||||
const tidToCount = {};
|
||||
postObjs.forEach((post) => {
|
||||
@@ -93,7 +105,8 @@ module.exports = function (Topics) {
|
||||
tidToCount[post.tid] += 1;
|
||||
});
|
||||
|
||||
return _.uniq(postObjs.map(post => String(post.tid))).sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
|
||||
return _.uniq(postObjs.map(post => String(post.tid)))
|
||||
.sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
|
||||
}
|
||||
|
||||
async function getWatchedTopics(params) {
|
||||
|
||||
Reference in New Issue
Block a user