fix: #10273, properly calculate item count for best/controversial

isekai-main
Barış Soner Uşaklı 3 years ago
parent e49b31f0c1
commit d70ce3a937

@ -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);
}

Loading…
Cancel
Save