Remove duplicated code to evict entries. (#14410)
This code was factored out to a method, but also left in-place. Calling this twice in a row makes no sense: the first call will reduce the size appropriately, but the loop will immediately exit since the cache size was already reduced.
This commit is contained in:
parent
b2c2b03079
commit
13ca8bb2fc
|
@ -0,0 +1 @@
|
||||||
|
Remove unreachable code.
|
|
@ -72,7 +72,7 @@ class StreamChangeCache:
|
||||||
items from the cache.
|
items from the cache.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: Whether the cache changed size or not.
|
Whether the cache changed size or not.
|
||||||
"""
|
"""
|
||||||
new_size = math.floor(self._original_max_size * factor)
|
new_size = math.floor(self._original_max_size * factor)
|
||||||
if new_size != self._max_size:
|
if new_size != self._max_size:
|
||||||
|
@ -188,14 +188,8 @@ class StreamChangeCache:
|
||||||
self._entity_to_key[entity] = stream_pos
|
self._entity_to_key[entity] = stream_pos
|
||||||
self._evict()
|
self._evict()
|
||||||
|
|
||||||
# if the cache is too big, remove entries
|
|
||||||
while len(self._cache) > self._max_size:
|
|
||||||
k, r = self._cache.popitem(0)
|
|
||||||
self._earliest_known_stream_pos = max(k, self._earliest_known_stream_pos)
|
|
||||||
for entity in r:
|
|
||||||
del self._entity_to_key[entity]
|
|
||||||
|
|
||||||
def _evict(self) -> None:
|
def _evict(self) -> None:
|
||||||
|
# if the cache is too big, remove entries
|
||||||
while len(self._cache) > self._max_size:
|
while len(self._cache) > self._max_size:
|
||||||
k, r = self._cache.popitem(0)
|
k, r = self._cache.popitem(0)
|
||||||
self._earliest_known_stream_pos = max(k, self._earliest_known_stream_pos)
|
self._earliest_known_stream_pos = max(k, self._earliest_known_stream_pos)
|
||||||
|
@ -203,7 +197,6 @@ class StreamChangeCache:
|
||||||
self._entity_to_key.pop(entity, None)
|
self._entity_to_key.pop(entity, None)
|
||||||
|
|
||||||
def get_max_pos_of_last_change(self, entity: EntityType) -> int:
|
def get_max_pos_of_last_change(self, entity: EntityType) -> int:
|
||||||
|
|
||||||
"""Returns an upper bound of the stream id of the last change to an
|
"""Returns an upper bound of the stream id of the last change to an
|
||||||
entity.
|
entity.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue