From fd5f9822bdc615392777998619f8bf7de259ce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 8 Aug 2019 14:23:34 -0400 Subject: [PATCH] fix: #7823, fix topic move readding pids when topic is deleted --- src/categories/recentreplies.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index f5ec54632d..3e94cbf834 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -147,11 +147,14 @@ module.exports = function (Categories) { // terrible name, should be topics.moveTopicPosts Categories.moveRecentReplies = async function (tid, oldCid, cid) { await updatePostCount(tid, oldCid, cid); - const pids = await topics.getPids(tid); + const [pids, topicDeleted] = await Promise.all([ + topics.getPids(tid), + topics.getTopicField(tid, 'deleted'), + ]); await batch.processArray(pids, async function (pids) { - const postData = await posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'upvotes', 'downvotes']); - const timestamps = postData.map(p => p && p.timestamp); + const postData = await posts.getPostsFields(pids, ['pid', 'deleted', 'uid', 'timestamp', 'upvotes', 'downvotes']); + const bulkRemove = []; const bulkAdd = []; postData.forEach((post) => { @@ -163,9 +166,11 @@ module.exports = function (Categories) { } }); + const postsToReAdd = postData.filter(p => !p.deleted && !topicDeleted); + const timestamps = postsToReAdd.map(p => p && p.timestamp); await Promise.all([ db.sortedSetRemove('cid:' + oldCid + ':pids', pids), - db.sortedSetAdd('cid:' + cid + ':pids', timestamps, pids), + db.sortedSetAdd('cid:' + cid + ':pids', timestamps, postsToReAdd.map(p => p.pid)), db.sortedSetRemoveBulk(bulkRemove), db.sortedSetAddBulk(bulkAdd), ]);