mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-20 03:11:57 +01:00
refactor: update upgrade script to scan for missing tid:<tid>:recipients
This commit is contained in:
@@ -17,21 +17,46 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const bulkRemove = [];
|
const bulkRemove = [];
|
||||||
const deleteTids = new Set();
|
|
||||||
uids.forEach((uid, index) => {
|
uids.forEach((uid, index) => {
|
||||||
const userTids = userInboxes[index];
|
const userTids = userInboxes[index];
|
||||||
userTids.forEach((tid, tidIndex) => {
|
userTids.forEach((tid, tidIndex) => {
|
||||||
if (!exists[index][tidIndex]) {
|
if (!exists[index][tidIndex]) {
|
||||||
bulkRemove.push([`uid:${uid}:inbox`, tid]);
|
bulkRemove.push([`uid:${uid}:inbox`, tid]);
|
||||||
deleteTids.add(tid);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await db.sortedSetRemoveBulk(bulkRemove);
|
await db.sortedSetRemoveBulk(bulkRemove);
|
||||||
await db.deleteAll(Array.from(deleteTids).map(tid => `tid:${tid}:recipients`));
|
|
||||||
progress.incr(uids.length);
|
progress.incr(uids.length);
|
||||||
}, {
|
}, {
|
||||||
batch: 500,
|
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,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user