|
|
@ -1,10 +1,10 @@
|
|
|
|
'use strict';
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../../database');
|
|
|
|
const db = require('../../database');
|
|
|
|
const batch = require('../../batch');
|
|
|
|
const batch = require('../../batch');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|
name: 'Update chat messages to add roomId field',
|
|
|
|
name: 'Update chat messages to add roomId field',
|
|
|
|
timestamp: Date.UTC(2023, 6, 2),
|
|
|
|
timestamp: Date.UTC(2023, 6, 2),
|
|
|
@ -31,17 +31,12 @@ module.exports = {
|
|
|
|
|
|
|
|
|
|
|
|
await batch.processArray(allRoomIds, async (roomIds) => {
|
|
|
|
await batch.processArray(allRoomIds, async (roomIds) => {
|
|
|
|
const arrayOfRoomData = await db.getObjects(roomIds.map(roomId => `chat:room:${roomId}`));
|
|
|
|
const arrayOfRoomData = await db.getObjects(roomIds.map(roomId => `chat:room:${roomId}`));
|
|
|
|
|
|
|
|
for (const roomData of arrayOfRoomData) {
|
|
|
|
await Promise.all(roomIds.map(async (roomId, index) => {
|
|
|
|
if (roomData) {
|
|
|
|
const roomData = arrayOfRoomData[index];
|
|
|
|
|
|
|
|
if (!roomData) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const midsSeen = Object.create(null);
|
|
|
|
const midsSeen = Object.create(null);
|
|
|
|
|
|
|
|
const { roomId } = roomData;
|
|
|
|
await batch.processSortedSet(`chat:room:${roomId}:uids`, async (uids) => {
|
|
|
|
await batch.processSortedSet(`chat:room:${roomId}:uids`, async (uids) => {
|
|
|
|
for (const uid of uids) {
|
|
|
|
for (const uid of uids) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
|
|
|
|
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) {
|
|
|
@ -79,7 +74,8 @@ module.exports = {
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
batch: 500,
|
|
|
|
batch: 500,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|
batch: 500,
|
|
|
|
batch: 500,
|
|
|
|
});
|
|
|
|
});
|
|
|
|