From 75f52cadafe11d55b15f12e036f32665e049b588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 5 Mar 2026 20:09:55 -0500 Subject: [PATCH] refactor: update upgrade script to scan for missing tid::recipients --- .../4.9.2/clean_tid_recipients_zsets.js | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/upgrades/4.9.2/clean_tid_recipients_zsets.js b/src/upgrades/4.9.2/clean_tid_recipients_zsets.js index 2206e1c040..eab3a8f612 100644 --- a/src/upgrades/4.9.2/clean_tid_recipients_zsets.js +++ b/src/upgrades/4.9.2/clean_tid_recipients_zsets.js @@ -17,21 +17,46 @@ module.exports = { ); const bulkRemove = []; - const deleteTids = new Set(); uids.forEach((uid, index) => { const userTids = userInboxes[index]; userTids.forEach((tid, tidIndex) => { if (!exists[index][tidIndex]) { bulkRemove.push([`uid:${uid}:inbox`, tid]); - deleteTids.add(tid); } }); }); await db.sortedSetRemoveBulk(bulkRemove); - await db.deleteAll(Array.from(deleteTids).map(tid => `tid:${tid}:recipients`)); + progress.incr(uids.length); }, { batch: 500, }); + + + const tidKeys = await db.scan({ match: 'tid:*:recipients' }); + progress.total = tidKeys.length; + progress.current = 0; + progress.counter = 0; + await batch.processArray(tidKeys, async (keys) => { + const tids = []; + keys.forEach((key) => { + const tid = key.split(':')[1]; + if (tid) { + tids.push(tid); + } + }); + const exists = await db.exists(tids.map(tid => `topic:${tid}`)); + const bulkDelete = []; + tids.forEach((tid, index) => { + if (!exists[index]) { + bulkDelete.push(`tid:${tid}:recipients`); + } + }); + await db.deleteAll(bulkDelete); + + progress.incr(keys.length); + }, { + batch: 500, + }); }, };