diff --git a/src/controllers/accounts/posts.js b/src/controllers/accounts/posts.js index dabfd8ece8..1a81e1bcef 100644 --- a/src/controllers/accounts/posts.js +++ b/src/controllers/accounts/posts.js @@ -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); +}