From 499cdd57083da462eec0a66bf76be18a3c703101 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 22 Nov 2018 14:32:11 +0000 Subject: [FIX] fields: combine special values during onchange Consider a many2one field `foo_id` on model `bar`, with an inverse one2many field `bar_ids` on model `foo`. During an onchange, the statement bar.foo_id = foo puts a special value in cache to add `bar` to the value of `foo.bar_ids` without explicitly reading `foo.bar_ids`. Executing the above statement a second time, the cache of `foo.bar_ids` is no longer empty. This causes the actual value of `foo.bar_ids` to be read and updated. The issue is that this can be slow for large values of `foo.bar_ids`. Avoid reading the value of the one2many field by handling the case where the cache contains the special value: simply update the special value to take into account the second assignment. closes odoo/odoo#28982 --- odoo/api.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'odoo/api.py') diff --git a/odoo/api.py b/odoo/api.py index 21095854a70..903e1187329 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -982,6 +982,12 @@ class Cache(object): value = self._data[field][record.id].get(key, SpecialValue(None)) return default if isinstance(value, SpecialValue) else value + def get_special(self, record, field, default=None): + """ Return the special value of ``field`` for ``record``. """ + key = field.cache_key(record) + value = self._data[field][record.id].get(key) + return value.get if isinstance(value, SpecialValue) else default + def set_special(self, record, field, getter): """ Set the value of ``field`` for ``record`` to return ``getter()``. """ key = field.cache_key(record) -- cgit v1.2.3