mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #10273, properly calculate item count for best/controversial
This commit is contained in:
@@ -60,6 +60,10 @@ const templateToData = {
|
||||
const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });
|
||||
return { posts: postObjs, nextStart: stop + 1 };
|
||||
},
|
||||
getItemCount: async (sets) => {
|
||||
const counts = await Promise.all(sets.map(set => db.sortedSetCount(set, 1, '+inf')));
|
||||
return counts.reduce((acc, val) => acc + val, 0);
|
||||
},
|
||||
},
|
||||
'account/controversial': {
|
||||
type: 'posts',
|
||||
@@ -74,6 +78,10 @@ const templateToData = {
|
||||
const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });
|
||||
return { posts: postObjs, nextStart: stop + 1 };
|
||||
},
|
||||
getItemCount: async (sets) => {
|
||||
const counts = await Promise.all(sets.map(set => db.sortedSetCount(set, '-inf', -1)));
|
||||
return counts.reduce((acc, val) => acc + val, 0);
|
||||
},
|
||||
},
|
||||
'account/watched': {
|
||||
type: 'topics',
|
||||
@@ -194,7 +202,7 @@ async function getPostsFromUserSet(template, req, res, next) {
|
||||
});
|
||||
} else {
|
||||
result = await utils.promiseParallel({
|
||||
itemCount: settings.usePagination ? db.sortedSetsCardSum(sets) : 0,
|
||||
itemCount: getItemCount(sets, data, settings),
|
||||
itemData: getItemData(sets, data, req, start, stop),
|
||||
});
|
||||
}
|
||||
@@ -231,3 +239,13 @@ async function getItemData(sets, data, req, start, stop) {
|
||||
const method = data.type === 'topics' ? topics.getTopicsFromSet : posts.getPostSummariesFromSet;
|
||||
return await method(sets, req.uid, start, stop);
|
||||
}
|
||||
|
||||
async function getItemCount(sets, data, settings) {
|
||||
if (!settings.usePagination) {
|
||||
return 0;
|
||||
}
|
||||
if (data.getItemCount) {
|
||||
return await data.getItemCount(sets);
|
||||
}
|
||||
return await db.sortedSetsCardSum(sets);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user