Fixed #72 : Exception when get_results(id=10)

Fixed #74 : Keyword parameters are no longer recognized when a concept that redefines equality is created
Fixed #118 : RecursionError: maximum recursion depth exceeded
Fixed #119 : PreventCircularReferenceEvaluator
Fixed #121 : Plural are not updated when new elements are added
Fixed #123 : BaseCache : Values in cache can be evicted before being committed
Fixed #105 : TOO_MANY_ERROR is not the relevant error when results are filtered
This commit is contained in:
2021-09-09 10:57:01 +02:00
parent 54e5681c5a
commit 945807b375
36 changed files with 503 additions and 98 deletions
+23 -13
View File
@@ -1,6 +1,6 @@
from threading import RLock
from core.global_symbols import NotFound, Removed
from core.global_symbols import NotFound
from core.utils import sheerka_deepcopy
MAX_INITIALIZED_KEY = 100
@@ -97,9 +97,6 @@ class BaseCache:
:return:
"""
with self._lock:
if self._max_size and self._current_size >= self._max_size:
self.evict(self._max_size - self._current_size + 1)
if self._put(key, value, alt_sdp):
self._current_size += 1
@@ -227,19 +224,29 @@ class BaseCache:
"""
with self._lock:
nb_items = self._current_size if self._current_size < nb_items else nb_items
nb_to_delete = nb_items
while nb_items > 0:
key = next(iter(self._cache))
to_remove = []
iter_cache = iter(self._cache)
try:
while nb_items > 0:
key = next(iter_cache)
if key in self.to_add or key in self.to_remove:
continue # cannot remove an item that is not yet committed
else:
to_remove.append(key)
nb_items -= 1
except StopIteration:
pass
for key in to_remove:
del (self._cache[key])
try:
self._initialized_keys.remove(key)
except KeyError:
pass
nb_items -= 1
self._current_size -= nb_to_delete
self._current_size -= len(to_remove)
return nb_to_delete
return len(to_remove)
def evict_by_key(self, predicate):
"""
@@ -359,14 +366,17 @@ class BaseCache:
simple_copy = False
if value is not NotFound:
self._cache[key] = value if simple_copy else sheerka_deepcopy(value)
value = self._cache[key]
value = value if simple_copy else sheerka_deepcopy(value)
self._cache[key] = value
# update _current_size
if isinstance(value, (list, set)):
self._current_size += len(value)
else:
self._current_size += 1
if self._max_size and self._current_size > self._max_size:
self.evict(self._current_size - self._max_size)
else:
value = self._default
self._initialized_keys.add(key)
@@ -383,4 +393,4 @@ class BaseCache:
pass
def _delete(self, key, value, alt_sdp):
raise NotImplementedError()
raise NotImplementedError("_delete BaseCache")