Skip to content

Commit 7841c76

Browse files
committed
perf: eliminate userIds array, use only userIdSet with spread at call sites
1 parent e4e6298 commit 7841c76

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise
9292
const [mentions, highlightIds] = await Promise.all([getMentions(message), getUserIdsFromHighlights(room._id, message)]);
9393

9494
const { toAll, toHere, mentionIds } = mentions;
95-
const userIds = [...new Set([...mentionIds, ...highlightIds])];
95+
const userIdSet = new Set([...mentionIds, ...highlightIds]);
9696
const unreadCount = getUnreadSettingCount(room.t);
9797
const unreadAllMessages = unreadCount === 'all_messages';
9898

@@ -104,19 +104,19 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise
104104
const subs = await Subscriptions.findByRoomIdAndNotAlertOrOpenExcludingUserIds({
105105
roomId: room._id,
106106
uidsExclude: [message.u._id],
107-
uidsInclude: userIds,
107+
uidsInclude: [...userIdSet],
108108
onlyRead: !toAll && !toHere && !unreadAllMessages,
109109
}).toArray();
110110

111111
// Give priority to user mentions over group mentions
112-
if (userIds.length) {
113-
await Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, userIds, 1, userMentionInc);
112+
if (userIdSet.size) {
113+
await Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(room._id, [...userIdSet], 1, userMentionInc);
114114
} else if (toAll || toHere) {
115115
await Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, groupMentionInc);
116116
}
117117

118118
if (!toAll && !toHere && unreadAllMessages) {
119-
await Subscriptions.incUnreadForRoomIdExcludingUserIds(room._id, [...userIds, message.u._id], 1);
119+
await Subscriptions.incUnreadForRoomIdExcludingUserIds(room._id, [...userIdSet, message.u._id], 1);
120120
}
121121

122122
// update subscriptions of other members of the room
@@ -126,7 +126,7 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise
126126
]);
127127

128128
subs.forEach((sub) => {
129-
const hasUserMention = userIds.includes(sub.u._id);
129+
const hasUserMention = userIdSet.has(sub.u._id);
130130
const shouldIncUnread = hasUserMention || toAll || toHere || unreadAllMessages;
131131
void notifyOnSubscriptionChanged(
132132
{

0 commit comments

Comments
 (0)