[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
This commit is contained in:
Géry Debongnie
2018-11-15 15:26:49 +00:00
parent 92b4e2e866
commit 1bb15e0559
+4 -3
View File
@@ -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'],