fix: #11947, make user message has a numeric timestamp

isekai-main
Barış Soner Uşaklı 1 year ago
parent 1193fa04f3
commit 2d62a77248

@ -40,22 +40,27 @@ module.exports = {
const { roomId } = roomData; const { roomId } = roomData;
const uids = await db.getSortedSetRange(`chat:room:${roomId}:uids`, 0, -1); 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 (userMessageData) => {
const uniqMids = mids.filter(mid => !midsSeen.hasOwnProperty(mid)); const uniqMessages = userMessageData.filter(m => !midsSeen.hasOwnProperty(m.value));
const uniqMids = uniqMessages.map(m => m.value);
if (!uniqMids.length) { if (!uniqMids.length) {
return; return;
} }
let messageData = await db.getObjects(uniqMids.map(mid => `message:${mid}`)); let messageData = await db.getObjects(uniqMids.map(mid => `message:${mid}`));
messageData.forEach((m, idx) => { messageData.forEach((m, idx) => {
if (m) { if (m && uniqMessages[idx]) {
m.mid = parseInt(uniqMids[idx], 10); m.mid = parseInt(uniqMids[idx], 10);
m.timestamp = m.timestamp || uniqMessages[idx].score || 0;
} }
}); });
messageData = messageData.filter(Boolean); messageData = messageData.filter(Boolean);
const bulkSet = messageData.map( const bulkSet = messageData.map(
msg => [`message:${msg.mid}`, { roomId: roomId }] msg => [`message:${msg.mid}`, {
roomId: roomId,
timestamp: m.timestamp,
}]
); );
await db.setObjectBulk(bulkSet); await db.setObjectBulk(bulkSet);
@ -69,6 +74,7 @@ module.exports = {
}); });
}, { }, {
batch: 500, batch: 500,
withScores: true,
}); });
// 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`);

Loading…
Cancel
Save