From fd35dd17b1f9de4469fe27baa264db816c23dbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 26 Apr 2024 12:12:48 -0400 Subject: [PATCH] make /top faster too --- src/topics/sorted.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/topics/sorted.js b/src/topics/sorted.js index 81f6f5be5a..f423bd1c2a 100644 --- a/src/topics/sorted.js +++ b/src/topics/sorted.js @@ -47,7 +47,10 @@ module.exports = function (Topics) { if (params.sort === 'posts') { tids = await getTidsWithMostPostsInTerm(params.cids, params.uid, params.term); } else { - tids = await Topics.getLatestTidsFromSet('topics:tid', 0, -1, params.term); + const cids = await getCids(params.cids, params.uid); + tids = await Topics.getLatestTidsFromSet( + cids.map(cid => `cid:${cid}:tids:create`), 0, -1, params.term + ); } if (params.filter === 'watched') { @@ -84,14 +87,18 @@ module.exports = function (Topics) { return 'topics:recent'; } - async function getTidsWithMostPostsInTerm(cids, uid, term) { + async function getCids(cids, uid) { if (Array.isArray(cids)) { cids = await privileges.categories.filterCids('topics:read', cids, uid); } else { cids = await categories.getCidsByPrivilege('categories:cid', uid, 'topics:read'); cids = cids.filter(cid => cid !== -1); } + return cids; + } + async function getTidsWithMostPostsInTerm(cids, uid, term) { + cids = await getCids(cids, uid); const pids = await db.getSortedSetRevRangeByScore( cids.map(cid => `cid:${cid}:pids`), 0,