fix: guard against infinite loop during topic purge batch call

This commit is contained in:
Julian Lam
2024-06-10 13:50:03 -04:00
parent 57913be591
commit 6272d059e7

View File

@@ -64,6 +64,7 @@ module.exports = function (Topics) {
const mainPid = await Topics.getTopicField(tid, 'mainPid'); const mainPid = await Topics.getTopicField(tid, 'mainPid');
await batch.processSortedSet(`tid:${tid}:posts`, async (pids) => { await batch.processSortedSet(`tid:${tid}:posts`, async (pids) => {
await posts.purge(pids, uid); await posts.purge(pids, uid);
await db.sortedSetRemove(`tid:${tid}:posts`, pids); // Guard against infinite loop if pid already does not exist in db
}, { alwaysStartAt: 0, batch: 500 }); }, { alwaysStartAt: 0, batch: 500 });
await posts.purge(mainPid, uid); await posts.purge(mainPid, uid);
await Topics.purge(tid, uid); await Topics.purge(tid, uid);