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

Commit

Permalink
Create singletons for StateFilter.{all,none}() (#11836)
Browse files Browse the repository at this point in the history
No point recreating these for each call, since they are frozen
  • Loading branch information
richvdh authored Jan 27, 2022
1 parent fd65139 commit 57e4786
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/11836.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor performance improvement in room state lookup.
14 changes: 9 additions & 5 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ def __attrs_post_init__(self):

@staticmethod
def all() -> "StateFilter":
"""Creates a filter that fetches everything.
"""Returns a filter that fetches everything.
Returns:
The new state filter.
The state filter.
"""
return StateFilter(types=frozendict(), include_others=True)
return _ALL_STATE_FILTER

@staticmethod
def none() -> "StateFilter":
"""Creates a filter that fetches nothing.
"""Returns a filter that fetches nothing.
Returns:
The new state filter.
"""
return StateFilter(types=frozendict(), include_others=False)
return _NONE_STATE_FILTER

@staticmethod
def from_types(types: Iterable[Tuple[str, Optional[str]]]) -> "StateFilter":
Expand Down Expand Up @@ -527,6 +527,10 @@ def approx_difference(self, other: "StateFilter") -> "StateFilter":
)


_ALL_STATE_FILTER = StateFilter(types=frozendict(), include_others=True)
_NONE_STATE_FILTER = StateFilter(types=frozendict(), include_others=False)


class StateGroupStorage:
"""High level interface to fetching state for event."""

Expand Down

0 comments on commit 57e4786

Please sign in to comment.