Skip to content

Commit

Permalink
fix: #11947, make user message has a numeric timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 23, 2023
1 parent 1193fa0 commit 2d62a77
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/upgrades/3.3.0/chat_room_refactor.js
Expand Up @@ -40,22 +40,27 @@ module.exports = {
const { roomId } = roomData;
const uids = await db.getSortedSetRange(`chat:room:${roomId}:uids`, 0, -1);
for (const uid of uids) {
await batch.processSortedSet(`uid:${uid}:chat:room:${roomId}:mids`, async (mids) => {
const uniqMids = mids.filter(mid => !midsSeen.hasOwnProperty(mid));
await batch.processSortedSet(`uid:${uid}:chat:room:${roomId}:mids`, async (userMessageData) => {
const uniqMessages = userMessageData.filter(m => !midsSeen.hasOwnProperty(m.value));
const uniqMids = uniqMessages.map(m => m.value);
if (!uniqMids.length) {
return;
}

let messageData = await db.getObjects(uniqMids.map(mid => `message:${mid}`));
messageData.forEach((m, idx) => {
if (m) {
if (m && uniqMessages[idx]) {
m.mid = parseInt(uniqMids[idx], 10);
m.timestamp = m.timestamp || uniqMessages[idx].score || 0;
}
});
messageData = messageData.filter(Boolean);

const bulkSet = messageData.map(
msg => [`message:${msg.mid}`, { roomId: roomId }]
msg => [`message:${msg.mid}`, {
roomId: roomId,
timestamp: m.timestamp,

Check failure on line 62 in src/upgrades/3.3.0/chat_room_refactor.js

View workflow job for this annotation

GitHub Actions / Lint and test (ubuntu-latest, 18, mongo-dev)

'm' is not defined
}]
);

await db.setObjectBulk(bulkSet);
Expand All @@ -69,6 +74,7 @@ module.exports = {
});
}, {
batch: 500,
withScores: true,
});
// eslint-disable-next-line no-await-in-loop
await db.deleteAll(`uid:${uid}:chat:room:${roomId}:mids`);
Expand Down

0 comments on commit 2d62a77

Please sign in to comment.