summaryrefslogtreecommitdiff
path: root/addons/mail/models
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2019-02-12 14:20:50 +0000
committerAlexandre Kühn <aku@odoo.com>2019-02-12 14:38:32 +0000
commit98e3ca4e671dbf45a4db9e730a46e65497e46df3 (patch)
treed9660ec8ceb5d53b4654bfe1214a0f829c7cb836 /addons/mail/models
parent055ca53c208b952bd746031f1fa5239173739726 (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/models')
-rw-r--r--addons/mail/models/mail_channel.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index 2b5bfe2a2db..180a995a68f 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -745,20 +745,21 @@ class Channel(models.Model):
@api.multi
def channel_fetched(self):
""" Broadcast the channel_fetched notification to channel members
+ :param channel_ids : list of channel id that has been fetched by current user
"""
- self.ensure_one()
- if not self.channel_message_ids.ids:
- return
- last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message
- self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]).write({
- 'fetched_message_id': last_message_id,
- })
- data = {
- 'info': 'channel_fetched',
- 'last_message_id': last_message_id,
- 'partner_id': self.env.user.partner_id.id,
- }
- self.env['bus.bus'].sendmany([[(self._cr.dbname, 'mail.channel', self.id), data]])
+ for channel in self:
+ if not channel.channel_message_ids.ids:
+ return
+ last_message_id = channel.channel_message_ids.ids[0] # zero is the index of the last message
+ self.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', self.env.user.partner_id.id)]).write({
+ 'fetched_message_id': last_message_id,
+ })
+ data = {
+ 'info': 'channel_fetched',
+ 'last_message_id': last_message_id,
+ 'partner_id': self.env.user.partner_id.id,
+ }
+ self.env['bus.bus'].sendmany([[(self._cr.dbname, 'mail.channel', channel.id), data]])
@api.multi
def channel_invite(self, partner_ids):