Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove duplicated code to evict entries. (#14410)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clokep authored Nov 10, 2022
1 parent b2c2b03 commit 13ca8bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/14410.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unreachable code.
11 changes: 2 additions & 9 deletions synapse/util/caches/stream_change_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_cache_factor(self, factor: float) -> bool:
items from the cache.
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)
if new_size != self._max_size:
Expand Down Expand Up @@ -188,22 +188,15 @@ def entity_has_changed(self, entity: EntityType, stream_pos: int) -> None:
self._entity_to_key[entity] = stream_pos
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:
# 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:
self._entity_to_key.pop(entity, None)

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
entity.
"""
Expand Down

0 comments on commit 13ca8bb

Please sign in to comment.