diff options
| author | Géry Debongnie <ged@odoo.com> | 2018-11-15 11:11:34 +0000 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2018-11-15 15:24:27 +0000 |
| commit | 92b4e2e866363ecb1b62c2448d40a5fcfc481348 (patch) | |
| tree | d98fb432a0adb718dbdd1a3bbb92b0be5bc4b35d /addons/web/models | |
| parent | 662657f44bf494e6b7eb4248e025ef76c788bf9c (diff) | |
[FIX] web: fix performance issue with read_progress_bar
The read_progress_bar method is incredibly not efficient. It is also
wrong in other ways (for example, if 2 groups have same labels, there is
a collision). But let us talk about efficiency: it iterates on each
records on the domain, then, it computes some information. It is really
worse for selection fields: it performs a fields_get for each iteration.
This commit improves the situation by doing the fields_get only once.
Note that this is not the end of the story: this only has a small effect on
the performance of this method. It looks like there is a deeper issue in
some cases (kanban view for subscription, field 'activity_state')
Diffstat (limited to 'addons/web/models')
| -rw-r--r-- | addons/web/models/models.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/addons/web/models/models.py b/addons/web/models/models.py index 572f07333d2..2e3bd54788d 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -40,11 +40,14 @@ class Base(models.AbstractModel): records_values = self.search_read(domain or [], [progress_bar['field'], group_by]) data = {} + field_type = self._fields[group_by].type + if field_type == 'selection': + selection_labels = dict(self.fields_get()[group_by]['selection']) + for record_values in records_values: group_by_value = record_values[group_by] # Again, imitating what _read_group_format_result and _read_group_prepare_data do - field_type = self._fields[group_by].type if group_by_value and field_type in ['date', 'datetime']: locale = self._context.get('lang') or 'en_US' group_by_value = fields.Datetime.to_datetime(group_by_value) @@ -61,7 +64,7 @@ class Base(models.AbstractModel): locale=locale) if field_type == 'selection': - group_by_value = dict(self.fields_get()[group_by]['selection'])[group_by_value] + group_by_value = selection_labels[group_by_value] if type(group_by_value) == tuple: group_by_value = group_by_value[1] # FIXME should use technical value (0) |
