diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index c2304b14a3..f5ec54632d 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -37,7 +37,7 @@ module.exports = function (Categories) { }; Categories.updateRecentTidForCid = async function (cid) { - let recentTid; + let postData; let topicData; let index = 0; do { @@ -46,16 +46,16 @@ module.exports = function (Categories) { if (!pids.length) { return; } - recentTid = await posts.getPostField(pids[0], 'tid'); - if (!recentTid) { - return; + postData = await posts.getPostFields(pids[0], ['tid', 'deleted']); + + if (postData && postData.tid && !postData.deleted) { + topicData = await topics.getTopicData(postData.tid); } - topicData = await topics.getTopicData(recentTid); index += 1; } while (!topicData || topicData.deleted); - if (recentTid) { - await Categories.updateRecentTid(cid, recentTid); + if (postData && postData.tid) { + await Categories.updateRecentTid(cid, postData.tid); } }; diff --git a/src/categories/topics.js b/src/categories/topics.js index 00a646dfb4..78b272cf5f 100644 --- a/src/categories/topics.js +++ b/src/categories/topics.js @@ -169,11 +169,11 @@ module.exports = function (Categories) { const promises = [ db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid), db.incrObjectField('category:' + cid, 'post_count'), - Categories.updateRecentTid(cid, postData.tid), ]; if (!pinned) { promises.push(db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid)); } await Promise.all(promises); + await Categories.updateRecentTidForCid(cid); }; }; diff --git a/src/topics/tools.js b/src/topics/tools.js index 10e2b50400..84c6a1032e 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -207,7 +207,7 @@ module.exports = function (Topics) { await Promise.all([ categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1), categories.incrementCategoryFieldBy(cid, 'topic_count', 1), - categories.updateRecentTid(cid, tid), + categories.updateRecentTidForCid(cid), categories.updateRecentTidForCid(oldCid), Topics.setTopicFields(tid, { cid: cid,