[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 <xmo@odoo.com>
This commit is contained in:
Raphael Collet
2020-04-03 11:40:26 +00:00
co-authored by Xavier Morel
parent db276e4d99
commit b491ca0bb3
+4 -3
View File
@@ -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