[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.
This commit is contained in:
Denis Ledoux
2019-02-11 15:45:36 +00:00
committed by Raphael Collet
parent 600c8b3e65
commit 368751b938
+2 -2
View File
@@ -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``. """