From 1af835641e65fa813e99ec47bff5b4aef19f1c09 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 13 Mar 2026 13:19:29 -0400 Subject: [PATCH] fix: restored popular calculation behaviour that was broken by e2131d1d2e1c6f14cb8867ac7e22840da3f4c63f, removed followingOnly arg passing for popular --- src/topics/sorted.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/topics/sorted.js b/src/topics/sorted.js index 6756fbfe38..a37d249cb0 100644 --- a/src/topics/sorted.js +++ b/src/topics/sorted.js @@ -46,8 +46,8 @@ module.exports = function (Topics) { let tids; if (params.term !== 'alltime') { if (params.sort === 'posts') { - const { cids, uid, term, includeRemote, followingOnly } = params; - tids = await getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote, followingOnly }); + const { cids, uid, term, includeRemote } = params; + tids = await getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote }); } else { const cids = await getCids(params.cids, params.uid); tids = await Topics.getLatestTidsFromSet( @@ -132,26 +132,24 @@ module.exports = function (Topics) { return cids; } - async function getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote, followingOnly }) { + async function getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote }) { cids = await getCids(cids, uid, includeRemote); - const sets = cids.map(cid => `cid:${cid}:tids`); - if (followingOnly && sets.includes('cid:-1:tids')) { - sets.splice(sets.indexOf('cid:-1:tids'), 1, `uid:${uid}:inbox`); - } - const tids = await db.getSortedSetRevRangeByScore( + const sets = cids.map(cid => `cid:${cid}:pids`); + const pids = await db.getSortedSetRevRangeByScore( sets, 0, 1000, '+inf', Date.now() - Topics.getSinceFromTerm(term) ); + const postObjs = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['tid']); const tidToCount = {}; - tids.forEach((tid) => { - tidToCount[tid] = tidToCount[tid] || 0; - tidToCount[tid] += 1; + postObjs.forEach((post) => { + tidToCount[post.tid] = tidToCount[post.tid] || 0; + tidToCount[post.tid] += 1; }); - return _.uniq(tids) + return _.uniq(postObjs.map(post => String(post.tid))) .sort((t1, t2) => tidToCount[t2] - tidToCount[t1]); }