Skip to content

Commit

Permalink
fix: #8763
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 14, 2020
1 parent a481024 commit 331d236
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/controllers/accounts/profile.js
Expand Up @@ -82,9 +82,23 @@ async function getBestPosts(callerUid, userData) {
async function getPosts(callerUid, userData, setSuffix) {
const cids = await categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read');
const keys = cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':' + setSuffix);
const pids = await db.getSortedSetRevRange(keys, 0, 9);
const postData = await posts.getPostSummaryByPids(pids, callerUid, { stripTags: false });
return postData.filter(p => p && !p.deleted && p.topic && !p.topic.deleted);
let hasMorePosts = true;
let start = 0;
const count = 10;
const postData = [];
do {
/* eslint-disable no-await-in-loop */
const pids = await db.getSortedSetRevRange(keys, start, start + count - 1);
if (!pids.length || pids.length < count) {
hasMorePosts = false;
}
if (pids.length) {
const p = await posts.getPostSummaryByPids(pids, callerUid, { stripTags: false });
postData.push(...p.filter(p => p && !p.deleted && p.topic && !p.topic.deleted));
}
start += count;
} while (postData.length < count && hasMorePosts);
return postData.slice(0, count);
}

function addMetaTags(res, userData) {
Expand Down

0 comments on commit 331d236

Please sign in to comment.