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,36 +11,36 @@ module.exports = {
|
|||||||
method: async function () {
|
method: async function () {
|
||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
|
|
||||||
progress.total = await db.sortedSetCard(`chat:rooms`);
|
const allRoomIds = await db.getSortedSetRange(`chat:rooms`, 0, -1);
|
||||||
await batch.processSortedSet(`chat:rooms`, async (roomIds) => {
|
|
||||||
progress.incr(roomIds.length);
|
|
||||||
for (const roomId of roomIds) {
|
|
||||||
await batch.processSortedSet(`chat:room:${roomId}:mids`, async (mids) => {
|
|
||||||
let messageData = await db.getObjects(mids.map(mid => `message:${mid}`));
|
|
||||||
messageData.forEach((m, idx) => {
|
|
||||||
if (m) {
|
|
||||||
m.mid = parseInt(mids[idx], 10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
messageData = messageData.filter(Boolean);
|
|
||||||
|
|
||||||
const bulkSet = messageData.map(
|
progress.total = allRoomIds.length;
|
||||||
msg => [`message:${msg.mid}`, { mid: msg.mid }]
|
|
||||||
);
|
|
||||||
|
|
||||||
await db.setObjectBulk(bulkSet);
|
for (const roomId of allRoomIds) {
|
||||||
await db.sortedSetAdd(
|
await batch.processSortedSet(`chat:room:${roomId}:mids`, async (mids) => {
|
||||||
'messages:mid',
|
let messageData = await db.getObjects(mids.map(mid => `message:${mid}`));
|
||||||
messageData.map(msg => msg.timestamp),
|
messageData.forEach((m, idx) => {
|
||||||
messageData.map(msg => msg.mid)
|
if (m) {
|
||||||
);
|
m.mid = parseInt(mids[idx], 10);
|
||||||
}, {
|
}
|
||||||
batch: 500,
|
|
||||||
});
|
});
|
||||||
}
|
messageData = messageData.filter(Boolean);
|
||||||
}, {
|
|
||||||
batch: 500,
|
const bulkSet = messageData.map(
|
||||||
});
|
msg => [`message:${msg.mid}`, { mid: msg.mid }]
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.setObjectBulk(bulkSet);
|
||||||
|
await db.sortedSetAdd(
|
||||||
|
'messages:mid',
|
||||||
|
messageData.map(msg => msg.timestamp),
|
||||||
|
messageData.map(msg => msg.mid)
|
||||||
|
);
|
||||||
|
}, {
|
||||||
|
batch: 500,
|
||||||
|
});
|
||||||
|
progress.incr(1);
|
||||||
|
}
|
||||||
|
|
||||||
const count = await db.sortedSetCard(`messages:mid`);
|
const count = await db.sortedSetCard(`messages:mid`);
|
||||||
await db.setObjectField('global', 'messageCount', count);
|
await db.setObjectField('global', 'messageCount', count);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,47 +38,44 @@ module.exports = {
|
|||||||
if (roomData) {
|
if (roomData) {
|
||||||
const midsSeen = {};
|
const midsSeen = {};
|
||||||
const { roomId } = roomData;
|
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) {
|
for (const uid of uids) {
|
||||||
await batch.processSortedSet(`uid:${uid}:chat:room:${roomId}:mids`, async (mids) => {
|
await batch.processSortedSet(`uid:${uid}:chat:room:${roomId}:mids`, async (mids) => {
|
||||||
const uniqMids = mids.filter(mid => !midsSeen.hasOwnProperty(mid));
|
const uniqMids = mids.filter(mid => !midsSeen.hasOwnProperty(mid));
|
||||||
if (!uniqMids.length) {
|
if (!uniqMids.length) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let messageData = await db.getObjects(uniqMids.map(mid => `message:${mid}`));
|
||||||
|
messageData.forEach((m, idx) => {
|
||||||
|
if (m) {
|
||||||
|
m.mid = parseInt(uniqMids[idx], 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
let messageData = await db.getObjects(uniqMids.map(mid => `message:${mid}`));
|
|
||||||
messageData.forEach((m, idx) => {
|
|
||||||
if (m) {
|
|
||||||
m.mid = parseInt(uniqMids[idx], 10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
messageData = messageData.filter(Boolean);
|
|
||||||
|
|
||||||
const bulkSet = messageData.map(
|
|
||||||
msg => [`message:${msg.mid}`, { roomId: roomId }]
|
|
||||||
);
|
|
||||||
|
|
||||||
await db.setObjectBulk(bulkSet);
|
|
||||||
await db.sortedSetAdd(
|
|
||||||
`chat:room:${roomId}:mids`,
|
|
||||||
messageData.map(m => m.timestamp),
|
|
||||||
messageData.map(m => m.mid),
|
|
||||||
);
|
|
||||||
uniqMids.forEach((mid) => {
|
|
||||||
midsSeen[mid] = 1;
|
|
||||||
});
|
|
||||||
}, {
|
|
||||||
batch: 500,
|
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line no-await-in-loop
|
messageData = messageData.filter(Boolean);
|
||||||
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
|
|
||||||
}
|
const bulkSet = messageData.map(
|
||||||
progress.incr(uids.length);
|
msg => [`message:${msg.mid}`, { roomId: roomId }]
|
||||||
}, {
|
);
|
||||||
batch: 500,
|
|
||||||
});
|
await db.setObjectBulk(bulkSet);
|
||||||
const userCount = await db.sortedSetCard(`chat:room:${roomId}:uids`);
|
await db.sortedSetAdd(
|
||||||
await db.setObjectField(`chat:room:${roomId}`, 'userCount', userCount);
|
`chat:room:${roomId}:mids`,
|
||||||
|
messageData.map(m => m.timestamp),
|
||||||
|
messageData.map(m => m.mid),
|
||||||
|
);
|
||||||
|
uniqMids.forEach((mid) => {
|
||||||
|
midsSeen[mid] = 1;
|
||||||
|
});
|
||||||
|
}, {
|
||||||
|
batch: 500,
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
|
||||||
|
progress.incr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.setObjectField(`chat:room:${roomId}`, 'userCount', uids.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user