From 7ca99c77e7df145f7237f7c5f985de8ba9968551 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 18 Oct 2017 16:19:35 -0200 Subject: [PATCH] Improve room sync speed --- server/publications/room.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/server/publications/room.js b/server/publications/room.js index 90d60a340e24..0e9e6a1190a0 100644 --- a/server/publications/room.js +++ b/server/publications/room.js @@ -30,7 +30,7 @@ const fields = { }; -const roomMap = (record, fields) => { +const roomMap = (record) => { if (record._room) { return _.pick(record._room, ...Object.keys(fields)); } @@ -38,10 +38,6 @@ const roomMap = (record, fields) => { return {}; }; -function getFieldsForUserId(/*userId*/) { - return fields; -} - Meteor.methods({ 'rooms/get'(updatedAt) { let options = {fields}; @@ -56,7 +52,7 @@ Meteor.methods({ this.unblock(); options = { - fields: getFieldsForUserId(this.userId) + fields }; if (updatedAt instanceof Date) { @@ -92,17 +88,16 @@ Meteor.methods({ throw new Meteor.Error('error-no-permission', 'No permission', { method: 'getRoomByTypeAndName' }); } - return roomMap({_room: room}, getFieldsForUserId(this.userId)); + return roomMap({_room: room}); } }); RocketChat.models.Rooms.cache.on('sync', (type, room/*, diff*/) => { const records = RocketChat.models.Subscriptions.findByRoomId(room._id).fetch(); + + const _room = roomMap({_room: room}); for (const record of records) { - const user = RocketChat.models.Users.findOneById(record.u._id); - if (user && (user.statusConnection === 'online' || user.statusConnection === 'away')) { - RocketChat.Notifications.notifyUserInThisInstance(record.u._id, 'rooms-changed', type, roomMap({_room: room}, getFieldsForUserId(record.u._id))); - } + RocketChat.Notifications.notifyUserInThisInstance(record.u._id, 'rooms-changed', type, _room); } }); @@ -110,7 +105,7 @@ RocketChat.models.Subscriptions.on('changed', (type, subscription/*, diff*/) => if (type === 'inserted' || type === 'removed') { const room = RocketChat.models.Rooms.findOneById(subscription.rid); if (room) { - RocketChat.Notifications.notifyUserInThisInstance(subscription.u._id, 'rooms-changed', type, roomMap({_room: room}, getFieldsForUserId(subscription.u._id))); + RocketChat.Notifications.notifyUserInThisInstance(subscription.u._id, 'rooms-changed', type, roomMap({_room: room})); } } });