From b491ca0bb37dc3b4eb6366cb7fc7518219a59684 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 2 Apr 2020 06:45:54 +0000 Subject: [PATCH] [IMP] core: avoid duplicates in `depends` and `depends_context` Repeated calls to `registry.setup_models()` will eventually introduce many duplicates in the those attributes, which may slow down the determination of computation triggers. X-original-commit: 735e65f7ca45616881336121d10a874412446dcf Co-authored-by: Xavier Morel --- odoo/fields.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/odoo/fields.py b/odoo/fields.py index 2d38e9ff8e3..84d1dad8b40 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -473,7 +473,8 @@ class Field(MetaField('DummyField', (object,), {})): # display_name may depend on context['lang'] (`test_lp1071710`) if self.automatic and self.name == 'display_name' and model._rec_name: if model._fields[model._rec_name].base_field.translate: - self.depends_context += ('lang',) + if 'lang' not in self.depends_context: + self.depends_context += ('lang',) # # Setup of related fields @@ -2897,11 +2898,11 @@ class _RelationalMulti(_Relational): def _setup_regular_full(self, model): super(_RelationalMulti, self)._setup_regular_full(model) if isinstance(self.domain, list): - self.depends += tuple( + self.depends = tuple(unique(itertools.chain(self.depends, ( self.name + '.' + arg[0] for arg in self.domain if isinstance(arg, (tuple, list)) and isinstance(arg[0], str) - ) + )))) def create(self, record_values): """ Write the value of ``self`` on the given records, which have just