Skip to content
Snippets Groups Projects
Commit 8df090e2 authored by Johann's avatar Johann
Browse files

Optimize query - Highlight words

parent 95e348e8
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
mentionIds = [];
highlightsIds = [];
toAll = false;
highlights = RocketChat.models.Users.find({}, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
highlights = RocketChat.models.Users.findUsersByUsernames(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
if (message.mentions != null) {
message.mentions.forEach(function(mention) {
......
......@@ -74,7 +74,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
userIdsToNotify = [];
userIdsToPushNotify = [];
usersWithHighlights = [];
highlights = RocketChat.models.Users.find({}, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
highlights = RocketChat.models.Users.findUsersByUsernames(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
highlights.forEach(function (user) {
if (user && user.settings && user.settings.preferences && messageContainsHighlight(message, user.settings.preferences.highlights)) {
......
......@@ -131,6 +131,13 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
return @find(query, options)?.fetch?()?[0]?.lastLogin
findUsersByUsernames: (usernames, options) ->
query =
username:
$in: usernames
return @find query, options
# UPDATE
updateLastLoginById: (_id) ->
update =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment