Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve room sync speed #8529

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions server/publications/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ const fields = {
};


const roomMap = (record, fields) => {
const roomMap = (record) => {
if (record._room) {
return _.pick(record._room, ...Object.keys(fields));
}
console.log('Empty Room for Subscription', record);
return {};
};

function getFieldsForUserId(/*userId*/) {
return fields;
}

Meteor.methods({
'rooms/get'(updatedAt) {
let options = {fields};
Expand All @@ -56,7 +52,7 @@ Meteor.methods({
this.unblock();

options = {
fields: getFieldsForUserId(this.userId)
fields
};

if (updatedAt instanceof Date) {
Expand Down Expand Up @@ -92,25 +88,24 @@ 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);
}
});

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}));
}
}
});