diff options
| author | Alexandre Kühn <aku@odoo.com> | 2019-02-12 14:20:50 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2019-02-12 14:38:32 +0000 |
| commit | 98e3ca4e671dbf45a4db9e730a46e65497e46df3 (patch) | |
| tree | d9660ec8ceb5d53b4654bfe1214a0f829c7cb836 /addons/mail/static/src/js/services/mail_manager.js | |
| parent | 055ca53c208b952bd746031f1fa5239173739726 (diff) | |
[FIX] mail: throttle batched `channel_fetched` RPCs
Revision on https://github.com/odoo/odoo/commit/844fb2b51ea7cfa557b19466c0a53dde19433e7a
The commit above added the seen icon on messages in a channel.
However, since this feature, there was a performance issue
when opening the systray messaging menu with several pinned
channels: lots of RPCs are made, almost 1 for each preview
in the messaging menu.
The RPCs comes from the reception of the last message in the
channel, to let the current user notify that he has received
the messages in the channel.
Those RPCs were made for each channel, thus the more pinned
channels the more RPCs were made when opening the messaging
menu.
This commit fixes the issue by throttling and batching the RPCs.
To do so, instead of letting the channel model handle the RPC
`channel_fetched`, the mail service now handles it. This has
the advantage to throttle the RPC globally and to batch the
requests to notify that messages have been received on channels.
closes odoo/odoo#31026
Diffstat (limited to 'addons/mail/static/src/js/services/mail_manager.js')
| -rw-r--r-- | addons/mail/static/src/js/services/mail_manager.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/services/mail_manager.js b/addons/mail/static/src/js/services/mail_manager.js index 6a49cdf0183..2234ce29af7 100644 --- a/addons/mail/static/src/js/services/mail_manager.js +++ b/addons/mail/static/src/js/services/mail_manager.js @@ -52,6 +52,12 @@ var MailManager = AbstractService.extend({ */ start: function () { this._super.apply(this, arguments); + + this._throttleNotifyChannelFetched = _.throttle(this._notifyChannelFetched.bind(this), 3000); + // List of channel that have requested the service to notify when + // it has been fetched, so that throttled RPCs batch the ids. + this._toNotifyChannelFetchedIDs = []; + this._initializeInternalState(); this._listenOnBuses(); this._fetchMailStateFromServer(); @@ -338,6 +344,14 @@ var MailManager = AbstractService.extend({ } }, /** + * @param {Object} data + * @param {integer} data.channelID + */ + notifyChannelFetched: function (data) { + this._toNotifyChannelFetchedIDs = _.uniq(this._toNotifyChannelFetchedIDs.concat(data.channelID)); + this._throttleNotifyChannelFetched(); + }, + /** * @param {integer|string} threadID */ openThread: function (threadID) { @@ -921,6 +935,23 @@ var MailManager = AbstractService.extend({ return new Message(this, data); }, /** + * @private + * @returns {$.Promise} + */ + _notifyChannelFetched: function () { + var channelIDs = this._toNotifyChannelFetchedIDs; + this._toNotifyChannelFetchedIDs = []; + if (_.isEmpty(channelIDs)) { + // no channel to notify fetched + return $.when(); + } + return this._rpc({ + model: 'mail.channel', + method: 'channel_fetched', + args: [channelIDs], + }, { shadow: true }); + }, + /** * shows a popup to notify a new received message. * This will also rename the browser tab if this is not the active tab. * |
