From 1bb15e0559aaf15626d5e91e04ebf78cc10cbd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 15 Nov 2018 12:11:02 +0000 Subject: [PATCH] [FIX] mail: fix performance issue for activity view Fun fact: for the subscription model in odoo production database, the get_activity_data rpc takes 36s, and transfer 420mb (non gzipped) of data (when looking at all subscriptions). The main reason for that is that the get_activity_data method create a domain with all the res_ids (so, if you have 20k subscriptions, the domain will look like (res_id, in, [...20k ids]). This domain is given to read group, and the resulting groups (each with a domain key which includes those res_ids) will be sent back to the web client. As far as I can tell, the domain key is not used by the web client, so we send (number of groups)*(number of records) of useless data. This commit improves the situation in two different ways: - we only generate the domain if there is a domain at the beginning. This should greatly improve the performance when there is no current domain - we do not transfer the data to the web client --- addons/mail/models/mail_activity.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 4a29e788d95..9838b96a5cd 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -422,8 +422,10 @@ class MailActivity(models.Model): @api.model def get_activity_data(self, res_model, domain): - res = self.env[res_model].search(domain) - activity_domain = [('res_id', 'in', res.ids), ('res_model', '=', res_model)] + activity_domain = [('res_model', '=', res_model)] + if domain: + res = self.env[res_model].search(domain) + activity_domain.append(('res_id', 'in', res.ids)) grouped_activities = self.env['mail.activity'].read_group( activity_domain, ['res_id', 'activity_type_id', 'res_name:max(res_name)', 'ids:array_agg(id)', 'date_deadline:min(date_deadline)'], @@ -443,7 +445,6 @@ class MailActivity(models.Model): state = self._compute_state_from_date(group['date_deadline'], self.user_id.sudo().tz) activity_data[res_id][activity_type_id] = { 'count': group['__count'], - 'domain': group['__domain'], 'ids': group['ids'], 'state': state, 'o_closest_deadline': group['date_deadline'],