From 053ff510bb15a3e3f7232eb494f0562aedf6d4e9 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 26 Jul 2019 13:22:33 -0400 Subject: [PATCH] fix: #7788, fix another edge case ignore pids in topics that were purged/deleted --- src/categories/recentreplies.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 6ddf6b95c1..c2304b14a3 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -37,15 +37,26 @@ module.exports = function (Categories) { }; Categories.updateRecentTidForCid = async function (cid) { - const pids = await db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0); - if (!pids.length) { - return; + 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) { + return; + } + recentTid = await posts.getPostField(pids[0], 'tid'); + if (!recentTid) { + return; + } + topicData = await topics.getTopicData(recentTid); + index += 1; + } while (!topicData || topicData.deleted); + + if (recentTid) { + await Categories.updateRecentTid(cid, recentTid); } - const tid = await posts.getPostField(pids[0], 'tid'); - if (!tid) { - return; - } - await Categories.updateRecentTid(cid, tid); }; Categories.getRecentTopicReplies = async function (categoryData, uid) {