diff options
| author | Adrian Torres <adt@odoo.com> | 2020-01-03 08:12:03 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-01-21 08:28:36 +0000 |
| commit | be01db2f712952a6c1d3688c8587d9624ef5dcc5 (patch) | |
| tree | a152b7fbb78b6367dd129b72b3fe08bc1632169c /odoo/fields.py | |
| parent | 8645e31863fa76a737ce5cf79a41c95ce7853507 (diff) | |
[IMP] api: move cache_key to the Environment and cache it
Computing the `cache_key` turned out to be a big factor during the
lifespan of a `BaseModel.mapped` call and a lot of this time is spent
computing the same `cache_key` over and over.
These unnecessary computations can be easily reduced to a couple by
moving the `cache_key` method on the environment (instead of the field)
and by implementing a memo for that method. The rationale is that the
`cache_key` of a field does not change for a given environment.
The result of this patch is up to 50% faster `Field.__get__` which in
turn means a GLOBAL gain in performance, especially for methods /
functions that rely heavily on `__get__` such as `BaseModel.mapped`.
closes odoo/odoo#42674
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index 449544e2250..3982f9c00da 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -633,34 +633,6 @@ class Field(MetaField('DummyField', (object,), {})): return Property.search_multi(self.name, self.model_name, operator, value) # - # Cache key for context-dependent fields - # - - def cache_key(self, env): - """ Return the cache key corresponding to ``self.depends_context``. """ - - def get(key, get_context=env.context.get): - if key == 'company': - return env.company.id - elif key == 'uid': - return (env.uid, env.su) - elif key == 'active_test': - return get_context('active_test', self.context.get('active_test', True)) - else: - v = get_context(key) - try: hash(v) - except TypeError: - raise TypeError( - "Can only create cache keys from hashable values, " - "got non-hashable value {!r} at context key {!r} " - "(dependency of field {})".format(v, key, self) - ) from None # we don't need to chain the exception created 2 lines above - else: - return v - - return tuple(get(key) for key in self.depends_context) - - # # Setup of field triggers # |
