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

Remove duplicated code to evict entries. #14410

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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