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 });
|
const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });
|
||||||
return { posts: postObjs, nextStart: stop + 1 };
|
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': {
|
'account/controversial': {
|
||||||
type: 'posts',
|
type: 'posts',
|
||||||
@@ -74,6 +78,10 @@ const templateToData = {
|
|||||||
const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });
|
const postObjs = await posts.getPostSummaryByPids(pids, req.uid, { stripTags: false });
|
||||||
return { posts: postObjs, nextStart: stop + 1 };
|
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': {
|
'account/watched': {
|
||||||
type: 'topics',
|
type: 'topics',
|
||||||
@@ -194,7 +202,7 @@ async function getPostsFromUserSet(template, req, res, next) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
result = await utils.promiseParallel({
|
result = await utils.promiseParallel({
|
||||||
itemCount: settings.usePagination ? db.sortedSetsCardSum(sets) : 0,
|
itemCount: getItemCount(sets, data, settings),
|
||||||
itemData: getItemData(sets, data, req, start, stop),
|
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;
|
const method = data.type === 'topics' ? topics.getTopicsFromSet : posts.getPostSummariesFromSet;
|
||||||
return await method(sets, req.uid, start, stop);
|
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