Skip to content

Node.js based forum software built for the modern web

refactor: update upgrade script to scan for missing tid:<tid>:recipients

Barış Soner Uşaklı75f52cadafe1
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,
+ });
},
};