mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: upgrade script, get rid of nested processSortedSet
This commit is contained in:
@@ -11,10 +11,11 @@ module.exports = {
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
|
||||
progress.total = await db.sortedSetCard(`chat:rooms`);
|
||||
await batch.processSortedSet(`chat:rooms`, async (roomIds) => {
|
||||
progress.incr(roomIds.length);
|
||||
for (const roomId of roomIds) {
|
||||
const allRoomIds = await db.getSortedSetRange(`chat:rooms`, 0, -1);
|
||||
|
||||
progress.total = allRoomIds.length;
|
||||
|
||||
for (const roomId of allRoomIds) {
|
||||
await batch.processSortedSet(`chat:room:${roomId}:mids`, async (mids) => {
|
||||
let messageData = await db.getObjects(mids.map(mid => `message:${mid}`));
|
||||
messageData.forEach((m, idx) => {
|
||||
@@ -37,10 +38,9 @@ module.exports = {
|
||||
}, {
|
||||
batch: 500,
|
||||
});
|
||||
progress.incr(1);
|
||||
}
|
||||
}, {
|
||||
batch: 500,
|
||||
});
|
||||
|
||||
const count = await db.sortedSetCard(`messages:mid`);
|
||||
await db.setObjectField('global', 'messageCount', count);
|
||||
},
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
if (roomData) {
|
||||
const midsSeen = {};
|
||||
const { roomId } = roomData;
|
||||
await batch.processSortedSet(`chat:room:${roomId}:uids`, async (uids) => {
|
||||
const uids = await db.getSortedSetRange(`chat:room:${roomId}:uids`, 0, -1);
|
||||
for (const uid of uids) {
|
||||
await batch.processSortedSet(`uid:${uid}:chat:room:${roomId}:mids`, async (mids) => {
|
||||
const uniqMids = mids.filter(mid => !midsSeen.hasOwnProperty(mid));
|
||||
@@ -72,13 +72,10 @@ module.exports = {
|
||||
});
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
|
||||
progress.incr(1);
|
||||
}
|
||||
progress.incr(uids.length);
|
||||
}, {
|
||||
batch: 500,
|
||||
});
|
||||
const userCount = await db.sortedSetCard(`chat:room:${roomId}:uids`);
|
||||
await db.setObjectField(`chat:room:${roomId}`, 'userCount', userCount);
|
||||
|
||||
await db.setObjectField(`chat:room:${roomId}`, 'userCount', uids.length);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user