[NEW] Reduce the amount of DDP API calls on login screen (#11083)

pull/11097/head
Rodrigo Nascimento 7 years ago committed by Diego Sampaio
parent e10d3b4d82
commit 401e2e2277
  1. 6
      client/startup/startup.js
  2. 18
      packages/rocketchat-apps/client/communication/websockets.js
  3. 6
      packages/rocketchat-apps/client/orchestrator.js
  4. 4
      packages/rocketchat-authorization/client/lib/ChatPermissions.js
  5. 4
      packages/rocketchat-authorization/client/startup.js
  6. 4
      packages/rocketchat-autotranslate/client/lib/autotranslate.js
  7. 10
      packages/rocketchat-custom-sounds/client/lib/CustomSounds.js
  8. 4
      packages/rocketchat-custom-sounds/client/notifications/deleteCustomSound.js
  9. 4
      packages/rocketchat-custom-sounds/client/notifications/updateCustomSound.js
  10. 30
      packages/rocketchat-emoji-custom/client/lib/emojiCustom.js
  11. 4
      packages/rocketchat-importer/client/ImporterWebsocketReceiver.js
  12. 34
      packages/rocketchat-lib/client/lib/cachedCollection.js
  13. 3
      packages/rocketchat-lib/client/lib/settings.js
  14. 13
      packages/rocketchat-ui/client/lib/RoomManager.js

@ -77,12 +77,11 @@ Meteor.startup(function() {
}
};
Meteor.subscribe('userData');
Tracker.autorun(function(computation) {
if (!Meteor.userId() && !RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
return;
}
Meteor.subscribe('userData');
Meteor.subscribe('activeUsers');
computation.stop();
});
@ -114,6 +113,9 @@ Meteor.startup(function() {
if (RocketChat.getUserPreference(user, 'enableAutoAway')) {
const idleTimeLimit = RocketChat.getUserPreference(user, 'idleTimeLimit') || 300;
UserPresence.awayTime = idleTimeLimit * 1000;
} else {
delete UserPresence.awayTime;
UserPresence.stopTimer();
}
UserPresence.start();

@ -15,6 +15,18 @@ export class AppWebsocketReceiver {
this.orch = orch;
this.streamer = new Meteor.Streamer('apps');
RocketChat.CachedCollectionManager.onLogin(() => {
this.listenStreamerEvents();
});
this.listeners = {};
Object.keys(AppEvents).forEach((v) => {
this.listeners[AppEvents[v]] = [];
});
}
listenStreamerEvents() {
this.streamer.on(AppEvents.APP_ADDED, this.onAppAdded.bind(this));
this.streamer.on(AppEvents.APP_REMOVED, this.onAppRemoved.bind(this));
this.streamer.on(AppEvents.APP_UPDATED, this.onAppUpdated.bind(this));
@ -24,12 +36,6 @@ export class AppWebsocketReceiver {
this.streamer.on(AppEvents.COMMAND_DISABLED, this.onCommandDisabled.bind(this));
this.streamer.on(AppEvents.COMMAND_UPDATED, this.onCommandUpdated.bind(this));
this.streamer.on(AppEvents.COMMAND_REMOVED, this.onCommandDisabled.bind(this));
this.listeners = {};
Object.keys(AppEvents).forEach((v) => {
this.listeners[AppEvents[v]] = [];
});
}
registerListener(event, listener) {

@ -85,8 +85,10 @@ class AppClientOrchestrator {
Meteor.startup(function _rlClientOrch() {
window.Apps = new AppClientOrchestrator();
Meteor.call('apps/is-enabled', (error, isEnabled) => {
window.Apps.load(isEnabled);
RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.call('apps/is-enabled', (error, isEnabled) => {
window.Apps.load(isEnabled);
});
});
});

@ -1,8 +1,6 @@
RocketChat.authz.cachedCollection = new RocketChat.CachedCollection({
name: 'permissions',
eventType: 'onLogged',
userRelated: false
eventType: 'onLogged'
});
RocketChat.authz.cachedCollection.init();
this.ChatPermissions = RocketChat.authz.cachedCollection.collection;

@ -1,4 +1,6 @@
Meteor.subscribe('roles');
RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.subscribe('roles');
});
RocketChat.AdminBox.addOption({
href: 'admin-permissions',

@ -90,5 +90,7 @@ RocketChat.AutoTranslate = {
};
Meteor.startup(function() {
RocketChat.AutoTranslate.init();
RocketChat.CachedCollectionManager.onLogin(() => {
RocketChat.AutoTranslate.init();
});
});

@ -62,9 +62,11 @@ class CustomSounds {
RocketChat.CustomSounds = new CustomSounds;
Meteor.startup(() =>
Meteor.call('listCustomSounds', (error, result) => {
for (const sound of result) {
RocketChat.CustomSounds.add(sound);
}
RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.call('listCustomSounds', (error, result) => {
for (const sound of result) {
RocketChat.CustomSounds.add(sound);
}
});
})
);

@ -1,3 +1,5 @@
Meteor.startup(() =>
RocketChat.Notifications.onAll('deleteCustomSound', data => RocketChat.CustomSounds.remove(data.soundData))
RocketChat.CachedCollectionManager.onLogin(() =>
RocketChat.Notifications.onAll('deleteCustomSound', data => RocketChat.CustomSounds.remove(data.soundData))
)
);

@ -1,3 +1,5 @@
Meteor.startup(() =>
RocketChat.Notifications.onAll('updateCustomSound', data => RocketChat.CustomSounds.update(data.soundData))
RocketChat.CachedCollectionManager.onLogin(() =>
RocketChat.Notifications.onAll('updateCustomSound', data => RocketChat.CustomSounds.update(data.soundData))
)
);

@ -148,21 +148,23 @@ updateEmojiCustom = function(emojiData) {
};
Meteor.startup(() =>
Meteor.call('listEmojiCustom', (error, result) => {
RocketChat.emoji.packages.emojiCustom.emojisByCategory = { rocket: [] };
for (const emoji of result) {
RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.push(emoji.name);
RocketChat.emoji.packages.emojiCustom.list.push(`:${ emoji.name }:`);
RocketChat.emoji.list[`:${ emoji.name }:`] = emoji;
RocketChat.emoji.list[`:${ emoji.name }:`].emojiPackage = 'emojiCustom';
for (const alias of emoji['aliases']) {
RocketChat.emoji.packages.emojiCustom.list.push(`:${ alias }:`);
RocketChat.emoji.list[`:${ alias }:`] = {
emojiPackage: 'emojiCustom',
aliasOf: emoji.name
};
RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.call('listEmojiCustom', (error, result) => {
RocketChat.emoji.packages.emojiCustom.emojisByCategory = { rocket: [] };
for (const emoji of result) {
RocketChat.emoji.packages.emojiCustom.emojisByCategory.rocket.push(emoji.name);
RocketChat.emoji.packages.emojiCustom.list.push(`:${ emoji.name }:`);
RocketChat.emoji.list[`:${ emoji.name }:`] = emoji;
RocketChat.emoji.list[`:${ emoji.name }:`].emojiPackage = 'emojiCustom';
for (const alias of emoji['aliases']) {
RocketChat.emoji.packages.emojiCustom.list.push(`:${ alias }:`);
RocketChat.emoji.list[`:${ alias }:`] = {
emojiPackage: 'emojiCustom',
aliasOf: emoji.name
};
}
}
}
});
})
);

@ -3,7 +3,9 @@ class ImporterWebsocketReceiverDef {
this.streamer = new Meteor.Streamer('importers');
this.callbacks = [];
this.streamer.on('progress', this.progressUpdated.bind(this));
RocketChat.CachedCollectionManager.onLogin(() => {
this.streamer.on('progress', this.progressUpdated.bind(this));
});
}
progressUpdated(progress) {

@ -15,18 +15,22 @@ class CachedCollectionManager {
this.clearAllCacheOnLogout();
};
let connectionWasOnline = true;
Tracker.autorun(() => {
const connected = Meteor.connection.status().connected;
if (connected === true && connectionWasOnline === false) {
for (const cb of this.reconnectCb) {
cb();
// Wait 1s to start or the code will run before the connection and
// on first connection the `reconnect` callbacks will run
Meteor.setTimeout(() => {
let connectionWasOnline = true;
Tracker.autorun(() => {
const connected = Meteor.connection.status().connected;
if (connected === true && connectionWasOnline === false) {
for (const cb of this.reconnectCb) {
cb();
}
}
}
connectionWasOnline = connected;
});
connectionWasOnline = connected;
});
}, 1000);
Tracker.autorun(() => {
if (Meteor.userId() !== null) {
@ -103,6 +107,7 @@ class CachedCollection {
eventName,
eventType = 'onUser',
userRelated = true,
listenChangesForLoggedUsersOnly = false,
useSync = true,
useCache = true,
version = 7,
@ -119,6 +124,7 @@ class CachedCollection {
this.eventType = eventType;
this.useSync = useSync;
this.useCache = useCache;
this.listenChangesForLoggedUsersOnly = listenChangesForLoggedUsersOnly;
this.debug = debug;
this.version = version;
this.userRelated = userRelated;
@ -375,7 +381,13 @@ class CachedCollection {
});
}
this.setupListener();
if (this.listenChangesForLoggedUsersOnly) {
RocketChat.CachedCollectionManager.onLogin(() => {
this.setupListener();
});
} else {
this.setupListener();
}
});
}
}

@ -9,7 +9,8 @@
RocketChat.settings.cachedCollection = new RocketChat.CachedCollection({
name: 'public-settings',
eventType: 'onAll',
userRelated: false
userRelated: false,
listenChangesForLoggedUsersOnly: true
});
RocketChat.settings.collection = RocketChat.settings.cachedCollection.collection;

@ -298,10 +298,11 @@ export { RoomManager };
this.RoomManager = RoomManager;
RocketChat.callbacks.add('afterLogoutCleanUp', () => RoomManager.closeAllRooms(), RocketChat.callbacks.priority.MEDIUM, 'roommanager-after-logout-cleanup');
RocketChat.Notifications.onUser('subscriptions-changed', (action, sub) => {
ChatMessage.update({rid: sub.rid}, {$unset : {ignored : ''}}, {multi : true});
if (sub && sub.ignored) {
ChatMessage.update({rid: sub.rid, t: {$ne: 'command'}, 'u._id': { $in : sub.ignored }}, { $set: {ignored : true}}, {multi : true});
}
RocketChat.CachedCollectionManager.onLogin(() => {
RocketChat.Notifications.onUser('subscriptions-changed', (action, sub) => {
ChatMessage.update({rid: sub.rid}, {$unset : {ignored : ''}}, {multi : true});
if (sub && sub.ignored) {
ChatMessage.update({rid: sub.rid, t: {$ne: 'command'}, 'u._id': { $in : sub.ignored }}, { $set: {ignored : true}}, {multi : true});
}
});
});

Loading…
Cancel
Save