mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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 () {
|
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);
|
progress.total = allRoomIds.length;
|
||||||
for (const roomId of roomIds) {
|
|
||||||
|
for (const roomId of allRoomIds) {
|
||||||
await batch.processSortedSet(`chat:room:${roomId}:mids`, async (mids) => {
|
await batch.processSortedSet(`chat:room:${roomId}:mids`, async (mids) => {
|
||||||
let messageData = await db.getObjects(mids.map(mid => `message:${mid}`));
|
let messageData = await db.getObjects(mids.map(mid => `message:${mid}`));
|
||||||
messageData.forEach((m, idx) => {
|
messageData.forEach((m, idx) => {
|
||||||
@@ -37,10 +38,9 @@ module.exports = {
|
|||||||
}, {
|
}, {
|
||||||
batch: 500,
|
batch: 500,
|
||||||
});
|
});
|
||||||
|
progress.incr(1);
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
batch: 500,
|
|
||||||
});
|
|
||||||
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,7 +38,7 @@ 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));
|
||||||
@@ -72,13 +72,10 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
|
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
|
||||||
|
progress.incr(1);
|
||||||
}
|
}
|
||||||
progress.incr(uids.length);
|
|
||||||
}, {
|
await db.setObjectField(`chat:room:${roomId}`, 'userCount', uids.length);
|
||||||
batch: 500,
|
|
||||||
});
|
|
||||||
const userCount = await db.sortedSetCard(`chat:room:${roomId}:uids`);
|
|
||||||
await db.setObjectField(`chat:room:${roomId}`, 'userCount', userCount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user