From 368751b9389ea652cffc7864adef66aac59986d9 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 4 Feb 2019 13:57:22 +0000 Subject: [PATCH] [IMP] api: avoid `record.id` indirections The cache is quite time critical, as it is accessed millions times when reading multiple fields on hundred of thousands of records. Avoiding indirections and `if` statement when possible speeds up the cache access time. --- odoo/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/api.py b/odoo/api.py index ca9927739a5..1bf9ba05f90 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -964,13 +964,13 @@ class Cache(object): def get(self, record, field): """ Return the value of ``field`` for ``record``. """ key = record.env.cache_key(field) - value = self._data[key][field][record.id] + value = self._data[key][field][record._ids[0]] return value.get() if isinstance(value, SpecialValue) else value def set(self, record, field, value): """ Set the value of ``field`` for ``record``. """ key = record.env.cache_key(field) - self._data[key][field][record.id] = value + self._data[key][field][record._ids[0]] = value def remove(self, record, field): """ Remove the value of ``field`` for ``record``. """