From eaaa251ce1e71037de8b6a1ece15f30cee790b16 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 5 Jun 2020 13:22:33 +0000 Subject: [PATCH] [FIX] website_mail_channel: filter on found channel Before this commit, controller did 1. search all channels with an alias 2. search on the messages on mail.channel 3. map the number of messages with the channels The issue was that the list of messages in step 2 includes more channels than the ones found in step 1. The list of messages may be very big and some groups may be retrieved while not used in the small list of channels with an alias. This commit should improve performances while accessing the /groups page. closes odoo/odoo#52593 X-original-commit: 60e806f4ea8ce75390eb59620ec61a39b4d3ccd2 Signed-off-by: Martin Trigaux (mat) --- addons/website_mail_channel/controllers/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/website_mail_channel/controllers/main.py b/addons/website_mail_channel/controllers/main.py index 2207794f363..dd7de5fce26 100644 --- a/addons/website_mail_channel/controllers/main.py +++ b/addons/website_mail_channel/controllers/main.py @@ -44,9 +44,12 @@ class MailGroup(http.Controller): # compute statistics month_date = datetime.today() - relativedelta.relativedelta(months=1) - messages = request.env['mail.message'].read_group( - [('model', '=', 'mail.channel'), ('date', '>=', fields.Datetime.to_string(month_date)), ('message_type', '!=', 'notification')], - [], ['res_id']) + messages = request.env['mail.message'].read_group([ + ('model', '=', 'mail.channel'), + ('date', '>=', fields.Datetime.to_string(month_date)), + ('message_type', '!=', 'notification'), + ('res_id', 'in', groups.ids), + ], ['res_id'], ['res_id']) message_data = dict((message['res_id'], message['res_id_count']) for message in messages) group_data = dict(