mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
use cid:<cid>:pids instead of posts:pid
This commit is contained in:
@@ -45,7 +45,7 @@ module.exports = function (Topics) {
|
|||||||
let tids = [];
|
let tids = [];
|
||||||
if (params.term !== 'alltime') {
|
if (params.term !== 'alltime') {
|
||||||
if (params.sort === 'posts') {
|
if (params.sort === 'posts') {
|
||||||
tids = await getTidsWithMostPostsInTerm(params.term);
|
tids = await getTidsWithMostPostsInTerm(params.cids, params.uid, params.term);
|
||||||
} else {
|
} else {
|
||||||
tids = await Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term);
|
tids = await Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term);
|
||||||
}
|
}
|
||||||
@@ -84,8 +84,20 @@ module.exports = function (Topics) {
|
|||||||
return 'topics:recent';
|
return 'topics:recent';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTidsWithMostPostsInTerm(term) {
|
async function getTidsWithMostPostsInTerm(cids, uid, term) {
|
||||||
const pids = await db.getSortedSetRevRangeByScore('posts:pid', 0, 1000, '+inf', Date.now() - Topics.getSinceFromTerm(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 postObjs = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['tid']);
|
||||||
const tidToCount = {};
|
const tidToCount = {};
|
||||||
postObjs.forEach((post) => {
|
postObjs.forEach((post) => {
|
||||||
@@ -93,7 +105,8 @@ module.exports = function (Topics) {
|
|||||||
tidToCount[post.tid] += 1;
|
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) {
|
async function getWatchedTopics(params) {
|
||||||
|
|||||||
Reference in New Issue
Block a user