From 77550a50dbfe0c4699521bf5cea844ba75873129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 18 Jul 2023 17:19:57 -0400 Subject: [PATCH] fix: fallback for room timestamp --- src/upgrades/3.3.0/chat_room_owners.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/upgrades/3.3.0/chat_room_owners.js b/src/upgrades/3.3.0/chat_room_owners.js index 7d608af9d4..9824091e39 100644 --- a/src/upgrades/3.3.0/chat_room_owners.js +++ b/src/upgrades/3.3.0/chat_room_owners.js @@ -12,6 +12,8 @@ module.exports = { const { progress } = this; progress.total = await db.sortedSetCard('chat:rooms'); + const users = await db.getSortedSetRangeWithScores(`users:joindate`, 0, 0); + const timestamp = users.length ? users[0].score : Date.now(); await batch.processSortedSet('chat:rooms', async (roomIds) => { progress.incr(roomIds.length); @@ -19,9 +21,17 @@ module.exports = { roomIds.map(id => `chat:room:${id}`) ); + const arrayOfUids = await Promise.all( + roomIds.map(roomId => db.getSortedSetRangeWithScores(`chat:room:${roomId}:uids`, 0, 0)) + ); + const bulkAdd = []; - roomData.forEach((room) => { - if (room && room.roomId && room.owner && room.timestamp) { + roomData.forEach((room, idx) => { + if (room && room.roomId && room.owner) { + // if room doesn't have timestamp for some reason use the first user timestamp + room.timestamp = room.timestamp || ( + arrayOfUids[idx].length ? (arrayOfUids[idx][0].score || timestamp) : timestamp + ); bulkAdd.push([`chat:room:${room.roomId}:owners`, room.timestamp, room.owner]); } });