From 0d4a3775589f6a920b7bdf93a4e043abc9f2be4b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 12 Jan 2021 13:13:26 -0500 Subject: [PATCH] feat(topic-events): clear out topic events when a topic is purged --- src/topics/delete.js | 1 + src/topics/events.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/topics/delete.js b/src/topics/delete.js index 5c3ec308be..38c6ec4473 100644 --- a/src/topics/delete.js +++ b/src/topics/delete.js @@ -98,6 +98,7 @@ module.exports = function (Topics) { ], tid), deleteTopicFromCategoryAndUser(tid), Topics.deleteTopicTags(tid), + Topics.events.purge(tid), reduceCounters(tid), ]); plugins.hooks.fire('action:topic.purge', { topic: deletedTopic, uid: uid }); diff --git a/src/topics/events.js b/src/topics/events.js index dc5d80906f..64cae15ce8 100644 --- a/src/topics/events.js +++ b/src/topics/events.js @@ -129,3 +129,12 @@ Events.log = async (tid, payload) => { ({ events } = await plugins.hooks.fire('filter:topic.events.log', { events })); return events; }; + +Events.purge = async (tid) => { + // Should only be called on topic purge + const keys = [`topic:${tid}:events`]; + const eventIds = await db.getSortedSetRange(keys[0], 0, -1); + keys.push(...eventIds.map(id => `topicEvent:${id}`)); + + db.deleteAll(keys); +};