fix: #7788, fix another edge case

ignore pids in topics that were purged/deleted
v1.18.x
Baris Usakli 6 years ago
parent d98313b5f6
commit 053ff510bb

@ -37,15 +37,26 @@ module.exports = function (Categories) {
}; };
Categories.updateRecentTidForCid = async function (cid) { Categories.updateRecentTidForCid = async function (cid) {
const pids = await db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0); let recentTid;
let topicData;
let index = 0;
do {
/* eslint-disable no-await-in-loop */
const pids = await db.getSortedSetRevRange('cid:' + cid + ':pids', index, index);
if (!pids.length) { if (!pids.length) {
return; return;
} }
const tid = await posts.getPostField(pids[0], 'tid'); recentTid = await posts.getPostField(pids[0], 'tid');
if (!tid) { if (!recentTid) {
return; return;
} }
await Categories.updateRecentTid(cid, tid); topicData = await topics.getTopicData(recentTid);
index += 1;
} while (!topicData || topicData.deleted);
if (recentTid) {
await Categories.updateRecentTid(cid, recentTid);
}
}; };
Categories.getRecentTopicReplies = async function (categoryData, uid) { Categories.getRecentTopicReplies = async function (categoryData, uid) {

Loading…
Cancel
Save