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

Commit

Permalink
Fix up cache entry __len__
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jul 21, 2022
1 parent 5aaadfa commit 2e71dde
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,18 @@ def set_state_group(self, state_group: int) -> None:

def __len__(self) -> int:
# The len should is used to estimate how large this cache entry is, for
# cache eviction purposes. This is why if `self.state` is None it's fine
# to return 1.
# cache eviction purposes. This is why it's fine to return 1 if we're
# not storing any state.

return len(self._state) if self._state else 1
length = 0

if self._state:
length += len(self._state)

if self.delta_ids:
length += len(self.delta_ids)

return length or 1 # Make sure its not 0.


class StateHandler:
Expand Down

0 comments on commit 2e71dde

Please sign in to comment.