feat(topic-events): clear out topic events when a topic is purged

v1.18.x
Julian Lam 4 years ago
parent 8e93bf7362
commit 0d4a377558

@ -98,6 +98,7 @@ module.exports = function (Topics) {
], tid), ], tid),
deleteTopicFromCategoryAndUser(tid), deleteTopicFromCategoryAndUser(tid),
Topics.deleteTopicTags(tid), Topics.deleteTopicTags(tid),
Topics.events.purge(tid),
reduceCounters(tid), reduceCounters(tid),
]); ]);
plugins.hooks.fire('action:topic.purge', { topic: deletedTopic, uid: uid }); plugins.hooks.fire('action:topic.purge', { topic: deletedTopic, uid: uid });

@ -129,3 +129,12 @@ Events.log = async (tid, payload) => {
({ events } = await plugins.hooks.fire('filter:topic.events.log', { events })); ({ events } = await plugins.hooks.fire('filter:topic.events.log', { events }));
return 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);
};

Loading…
Cancel
Save