Make global cache depends on explicit context keys
This should prevent the invalidation of the cache when the context keys that are changed has no influence onn the global cache. issue3905 review6291002
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Make global cache depends on explicit context keys
|
||||
* Don't add to global cache Binary fields
|
||||
* Add MachMixin
|
||||
* Remove context, current_date and time from record rule evaluation
|
||||
|
||||
|
||||
@@ -105,29 +105,19 @@ class CursorInterface(object):
|
||||
Define generic interface for database cursor
|
||||
'''
|
||||
IN_MAX = 1000
|
||||
cache_keys = {'language', 'fuzzy_translation', '_datetime'}
|
||||
|
||||
def __init__(self):
|
||||
self.cache = {}
|
||||
|
||||
def get_cache(self, context=None):
|
||||
'''
|
||||
Return cache for the context
|
||||
|
||||
:param context: the context
|
||||
:return: the cache dictionary
|
||||
'''
|
||||
def get_cache(self):
|
||||
from trytond.cache import LRUDict
|
||||
from trytond.transaction import Transaction
|
||||
user = Transaction().user
|
||||
if context is None:
|
||||
context = {}
|
||||
cache_ctx = context.copy()
|
||||
for i in ('_timestamp', '_delete', '_create_records',
|
||||
'_delete_records'):
|
||||
if i in cache_ctx:
|
||||
del cache_ctx[i]
|
||||
return self.cache.setdefault((user, repr(cache_ctx)),
|
||||
LRUDict(MODEL_CACHE_SIZE))
|
||||
context = Transaction().context
|
||||
keys = tuple(((key, context[key]) for key in sorted(self.cache_keys)
|
||||
if key in context))
|
||||
return self.cache.setdefault((user, keys), LRUDict(MODEL_CACHE_SIZE))
|
||||
|
||||
def execute(self, sql, params=None):
|
||||
'''
|
||||
|
||||
@@ -9,11 +9,14 @@ from ..tools import safe_eval, datetime_strftime
|
||||
from ..transaction import Transaction
|
||||
from ..pool import Pool
|
||||
from .time_locale import TIME_LOCALE
|
||||
from ..backend.database import CursorInterface
|
||||
|
||||
warnings.filterwarnings('ignore', "", ImportWarning)
|
||||
from locale import CHAR_MAX
|
||||
warnings.resetwarnings()
|
||||
|
||||
CursorInterface.cache_keys.add('translate_name')
|
||||
|
||||
__all__ = [
|
||||
'Lang',
|
||||
]
|
||||
|
||||
@@ -1053,7 +1053,7 @@ class ModelSQL(ModelStorage):
|
||||
cursor.execute(*select)
|
||||
|
||||
rows = cursor.dictfetchmany(cursor.IN_MAX)
|
||||
cache = cursor.get_cache(transaction.context)
|
||||
cache = cursor.get_cache()
|
||||
if cls.__name__ not in cache:
|
||||
cache[cls.__name__] = LRUDict(RECORD_CACHE_SIZE)
|
||||
delete_records = transaction.delete_records.setdefault(cls.__name__,
|
||||
|
||||
@@ -1137,7 +1137,7 @@ class ModelStorage(Model):
|
||||
else:
|
||||
self._ids = [id]
|
||||
|
||||
self._cursor_cache = self._cursor.get_cache(self._context)
|
||||
self._cursor_cache = self._cursor.get_cache()
|
||||
|
||||
if _local_cache is not None:
|
||||
self._local_cache = _local_cache
|
||||
@@ -1300,7 +1300,7 @@ class ModelStorage(Model):
|
||||
if data['id'] == self.id and fname == name:
|
||||
value = fvalue
|
||||
if (field._type not in ('many2one', 'one2one', 'one2many',
|
||||
'many2many', 'reference')
|
||||
'many2many', 'reference', 'binary')
|
||||
and not isinstance(field, fields.Function)):
|
||||
continue
|
||||
if data['id'] not in self._local_cache:
|
||||
|
||||
Reference in New Issue
Block a user