v1.18.x
Barış Soner Uşaklı 4 years ago
parent a481024d27
commit 331d236f6e

@ -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) {

Loading…
Cancel
Save