Skip to content

Commit

Permalink
feat(topic-events): clear out topic events when a topic is purged
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jan 27, 2021
1 parent 8e93bf7 commit 0d4a377
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/topics/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
9 changes: 9 additions & 0 deletions src/topics/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 0d4a377

Please sign in to comment.