From 76551c7123ab3b988cc107fd4c2f4cbb970ef100 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 22 Aug 2024 11:17:27 -0400 Subject: [PATCH] fix: #12751, topics:recent zset not updated when tid moved in/out of cid -1 --- src/topics/recent.js | 4 ++-- src/topics/tools.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/topics/recent.js b/src/topics/recent.js index b331ed4535..8cc84c54c7 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -76,14 +76,14 @@ module.exports = function (Topics) { // Topics in /world are excluded from /recent const cid = await Topics.getTopicField(tid, 'cid'); if (cid === -1) { - return; + return await db.sortedSetRemove('topics:recent', data.tid); } if (plugins.hooks.hasListeners('filter:topics.updateRecent')) { data = await plugins.hooks.fire('filter:topics.updateRecent', data); } if (data && data.tid && data.timestamp) { - await db.sortedSetAdd(`topics:recent`, data.timestamp, data.tid); + await db.sortedSetAdd('topics:recent', data.timestamp, data.tid); } }; }; diff --git a/src/topics/tools.js b/src/topics/tools.js index cadeb95563..e403383295 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -285,6 +285,12 @@ module.exports = function (Topics) { Topics.updateCategoryTagsCount([oldCid, cid], tags), Topics.events.log(tid, { type: 'move', uid: data.uid, fromCid: oldCid }), ]); + + // Update entry in recent topics zset — must come after hash update + if (oldCid === -1 || cid === -1) { + Topics.updateRecent(tid, topicData.lastposttime); // no await req'd + } + const hookData = _.clone(data); hookData.fromCid = oldCid; hookData.toCid = cid;