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

Commit 57e4786

Browse files
authored
Create singletons for StateFilter.{all,none}() (#11836)
No point recreating these for each call, since they are frozen
1 parent fd65139 commit 57e4786

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

changelog.d/11836.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor performance improvement in room state lookup.

synapse/storage/state.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ def __attrs_post_init__(self):
7474

7575
@staticmethod
7676
def all() -> "StateFilter":
77-
"""Creates a filter that fetches everything.
77+
"""Returns a filter that fetches everything.
7878
7979
Returns:
80-
The new state filter.
80+
The state filter.
8181
"""
82-
return StateFilter(types=frozendict(), include_others=True)
82+
return _ALL_STATE_FILTER
8383

8484
@staticmethod
8585
def none() -> "StateFilter":
86-
"""Creates a filter that fetches nothing.
86+
"""Returns a filter that fetches nothing.
8787
8888
Returns:
8989
The new state filter.
9090
"""
91-
return StateFilter(types=frozendict(), include_others=False)
91+
return _NONE_STATE_FILTER
9292

9393
@staticmethod
9494
def from_types(types: Iterable[Tuple[str, Optional[str]]]) -> "StateFilter":
@@ -527,6 +527,10 @@ def approx_difference(self, other: "StateFilter") -> "StateFilter":
527527
)
528528

529529

530+
_ALL_STATE_FILTER = StateFilter(types=frozendict(), include_others=True)
531+
_NONE_STATE_FILTER = StateFilter(types=frozendict(), include_others=False)
532+
533+
530534
class StateGroupStorage:
531535
"""High level interface to fetching state for event."""
532536

0 commit comments

Comments
 (0)