mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 11:36:29 +02:00
fix: restored popular calculation behaviour that was broken by e2131d1d2e, removed followingOnly arg passing for popular
This commit is contained in:
@@ -46,8 +46,8 @@ module.exports = function (Topics) {
|
|||||||
let tids;
|
let tids;
|
||||||
if (params.term !== 'alltime') {
|
if (params.term !== 'alltime') {
|
||||||
if (params.sort === 'posts') {
|
if (params.sort === 'posts') {
|
||||||
const { cids, uid, term, includeRemote, followingOnly } = params;
|
const { cids, uid, term, includeRemote } = params;
|
||||||
tids = await getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote, followingOnly });
|
tids = await getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote });
|
||||||
} else {
|
} else {
|
||||||
const cids = await getCids(params.cids, params.uid);
|
const cids = await getCids(params.cids, params.uid);
|
||||||
tids = await Topics.getLatestTidsFromSet(
|
tids = await Topics.getLatestTidsFromSet(
|
||||||
@@ -132,26 +132,24 @@ module.exports = function (Topics) {
|
|||||||
return cids;
|
return cids;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote, followingOnly }) {
|
async function getTidsWithMostPostsInTerm({ cids, uid, term, includeRemote }) {
|
||||||
cids = await getCids(cids, uid, includeRemote);
|
cids = await getCids(cids, uid, includeRemote);
|
||||||
const sets = cids.map(cid => `cid:${cid}:tids`);
|
const sets = cids.map(cid => `cid:${cid}:pids`);
|
||||||
if (followingOnly && sets.includes('cid:-1:tids')) {
|
const pids = await db.getSortedSetRevRangeByScore(
|
||||||
sets.splice(sets.indexOf('cid:-1:tids'), 1, `uid:${uid}:inbox`);
|
|
||||||
}
|
|
||||||
const tids = await db.getSortedSetRevRangeByScore(
|
|
||||||
sets,
|
sets,
|
||||||
0,
|
0,
|
||||||
1000,
|
1000,
|
||||||
'+inf',
|
'+inf',
|
||||||
Date.now() - Topics.getSinceFromTerm(term)
|
Date.now() - Topics.getSinceFromTerm(term)
|
||||||
);
|
);
|
||||||
|
const postObjs = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['tid']);
|
||||||
const tidToCount = {};
|
const tidToCount = {};
|
||||||
tids.forEach((tid) => {
|
postObjs.forEach((post) => {
|
||||||
tidToCount[tid] = tidToCount[tid] || 0;
|
tidToCount[post.tid] = tidToCount[post.tid] || 0;
|
||||||
tidToCount[tid] += 1;
|
tidToCount[post.tid] += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
return _.uniq(tids)
|
return _.uniq(postObjs.map(post => String(post.tid)))
|
||||||
.sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
|
.sort((t1, t2) => tidToCount[t2] - tidToCount[t1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user