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

Create singletons for StateFilter.{all,none}() #11836

Merged
merged 1 commit into from
Jan 27, 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/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