Skip to content

Node.js based forum software built for the modern web

use `cid:<cid>:pids` instead of posts:pid

Barış Soner Uşaklıf764a3ea5c01
diff --git a/src/topics/sorted.js b/src/topics/sorted.js
index c2f916718e..98292f0ddb 100644
--- a/src/topics/sorted.js
+++ b/src/topics/sorted.js
@@ -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, 1000, '+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) {