mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 21:45:47 +01:00
fix: fallback for room timestamp
This commit is contained in:
@@ -12,6 +12,8 @@ module.exports = {
|
|||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
|
|
||||||
progress.total = await db.sortedSetCard('chat:rooms');
|
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) => {
|
await batch.processSortedSet('chat:rooms', async (roomIds) => {
|
||||||
progress.incr(roomIds.length);
|
progress.incr(roomIds.length);
|
||||||
@@ -19,9 +21,17 @@ module.exports = {
|
|||||||
roomIds.map(id => `chat:room:${id}`)
|
roomIds.map(id => `chat:room:${id}`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const arrayOfUids = await Promise.all(
|
||||||
|
roomIds.map(roomId => db.getSortedSetRangeWithScores(`chat:room:${roomId}:uids`, 0, 0))
|
||||||
|
);
|
||||||
|
|
||||||
const bulkAdd = [];
|
const bulkAdd = [];
|
||||||
roomData.forEach((room) => {
|
roomData.forEach((room, idx) => {
|
||||||
if (room && room.roomId && room.owner && room.timestamp) {
|
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]);
|
bulkAdd.push([`chat:room:${room.roomId}:owners`, room.timestamp, room.owner]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user