[FIX] mail: fix performance issue with large channels

When a user is subscribed to a channel with many messages,
the discuss initial rpc /mail/client_action can become very
slow (in production, the rpc took > 20s when subscribed to
the Community mailing list).  This is due to the query in
_get_message_unread, counting the number of unread messages.

This commit adds an index on the relation mail_channel_partner,
this allows postgres to perform only index lookups, and speeds
up the query by 2 order of magnitudes.
This commit is contained in:
Géry Debongnie
2016-04-27 17:00:20 +02:00
parent 7d25dd5618
commit 7922370f12
+5
View File
@@ -214,6 +214,11 @@ class Channel(models.Model):
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs)
return message
def init(self, cr):
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('mail_channel_partner_seen_message_id_idx',))
if not cr.fetchone():
cr.execute('CREATE INDEX mail_channel_partner_seen_message_id_idx ON mail_channel_partner (channel_id,partner_id,seen_message_id)')
#------------------------------------------------------
# Instant Messaging API
#------------------------------------------------------