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

No point recreating these for each call, since they are frozen
pull/11843/head
Richard van der Hoff 2022-01-27 10:54:27 +00:00 committed by GitHub
parent fd65139714
commit 57e4786e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

1
changelog.d/11836.misc Normal file
View File

@ -0,0 +1 @@
Minor performance improvement in room state lookup.

View File

@ -74,21 +74,21 @@ class StateFilter:
@staticmethod @staticmethod
def all() -> "StateFilter": def all() -> "StateFilter":
"""Creates a filter that fetches everything. """Returns a filter that fetches everything.
Returns: Returns:
The new state filter. The state filter.
""" """
return StateFilter(types=frozendict(), include_others=True) return _ALL_STATE_FILTER
@staticmethod @staticmethod
def none() -> "StateFilter": def none() -> "StateFilter":
"""Creates a filter that fetches nothing. """Returns a filter that fetches nothing.
Returns: Returns:
The new state filter. The new state filter.
""" """
return StateFilter(types=frozendict(), include_others=False) return _NONE_STATE_FILTER
@staticmethod @staticmethod
def from_types(types: Iterable[Tuple[str, Optional[str]]]) -> "StateFilter": def from_types(types: Iterable[Tuple[str, Optional[str]]]) -> "StateFilter":
@ -527,6 +527,10 @@ class StateFilter:
) )
_ALL_STATE_FILTER = StateFilter(types=frozendict(), include_others=True)
_NONE_STATE_FILTER = StateFilter(types=frozendict(), include_others=False)
class StateGroupStorage: class StateGroupStorage:
"""High level interface to fetching state for event.""" """High level interface to fetching state for event."""