From 3e6bbe93af76120dd13aa162b1ae2d0c665eea06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 25 Jun 2019 08:47:31 +0000 Subject: [PATCH] [IMP] mail: call _get_tracked_fields in batch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit `_get_tracked_fields` was not called in batch because it took the `updated_fields` parameter, but this parameter is not used. By removing the parameter and calling the method in batch, creating 1000 products takes 20% less time. Part of task-1918881 closes odoo/odoo#34347 Signed-off-by: Xavier Dollé (xdo) --- addons/mail/models/mail_thread.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index e419c5430b8..720cf02c112 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -297,9 +297,9 @@ class MailThread(models.AbstractModel): # post track template if a tracked field changed if not self._context.get('mail_notrack'): track_threads = threads.with_lang() + tracked_fields = self._get_tracked_fields() for thread in track_threads: create_values = create_values_list[thread.id] - tracked_fields = self._get_tracked_fields(list(create_values)) changes = [field for field in tracked_fields if create_values.get(field)] # based on tracked field to stay consistent with write # we don't consider that a falsy field is a change, to stay consistent with previous implementation, @@ -318,7 +318,7 @@ class MailThread(models.AbstractModel): tracked_fields = None if not self._context.get('mail_notrack'): - tracked_fields = track_self._get_tracked_fields(list(values)) + tracked_fields = track_self._get_tracked_fields() if tracked_fields: initial_values = dict((record.id, dict((key, getattr(record, key)) for key in tracked_fields)) for record in track_self) @@ -547,9 +547,8 @@ class MailThread(models.AbstractModel): # ------------------------------------------------------ @api.model - def _get_tracked_fields(self, updated_fields): + def _get_tracked_fields(self): """ Return a structure of tracked fields for the current model. - :param list updated_fields: modified field names :return dict: a dict mapping field name to description, containing on_change fields """ tracked_fields = []