mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-12-15 17:38:48 -05:00
Add StateMap type alias (#6715)
This commit is contained in:
parent
7b14c4a018
commit
d386f2f339
14 changed files with 115 additions and 93 deletions
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import logging
|
||||
from collections import namedtuple
|
||||
from typing import Dict, Iterable, List, Set, Tuple
|
||||
|
||||
from six import iteritems
|
||||
from six.moves import range
|
||||
|
|
@ -26,6 +27,7 @@ from synapse.storage._base import SQLBaseStore
|
|||
from synapse.storage.data_stores.state.bg_updates import StateBackgroundUpdateStore
|
||||
from synapse.storage.database import Database
|
||||
from synapse.storage.state import StateFilter
|
||||
from synapse.types import StateMap
|
||||
from synapse.util.caches import get_cache_factor_for
|
||||
from synapse.util.caches.descriptors import cached
|
||||
from synapse.util.caches.dictionary_cache import DictionaryCache
|
||||
|
|
@ -133,17 +135,18 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _get_state_groups_from_groups(self, groups, state_filter):
|
||||
"""Returns the state groups for a given set of groups, filtering on
|
||||
types of state events.
|
||||
def _get_state_groups_from_groups(
|
||||
self, groups: List[int], state_filter: StateFilter
|
||||
):
|
||||
"""Returns the state groups for a given set of groups from the
|
||||
database, filtering on types of state events.
|
||||
|
||||
Args:
|
||||
groups(list[int]): list of state group IDs to query
|
||||
state_filter (StateFilter): The state filter used to fetch state
|
||||
groups: list of state group IDs to query
|
||||
state_filter: The state filter used to fetch state
|
||||
from the database.
|
||||
Returns:
|
||||
Deferred[dict[int, dict[tuple[str, str], str]]]:
|
||||
dict of state_group_id -> (dict of (type, state_key) -> event id)
|
||||
Deferred[Dict[int, StateMap[str]]]: Dict of state group to state map.
|
||||
"""
|
||||
results = {}
|
||||
|
||||
|
|
@ -199,18 +202,19 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
return state_filter.filter_state(state_dict_ids), not missing_types
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _get_state_for_groups(self, groups, state_filter=StateFilter.all()):
|
||||
def _get_state_for_groups(
|
||||
self, groups: Iterable[int], state_filter: StateFilter = StateFilter.all()
|
||||
):
|
||||
"""Gets the state at each of a list of state groups, optionally
|
||||
filtering by type/state_key
|
||||
|
||||
Args:
|
||||
groups (iterable[int]): list of state groups for which we want
|
||||
groups: list of state groups for which we want
|
||||
to get the state.
|
||||
state_filter (StateFilter): The state filter used to fetch state
|
||||
state_filter: The state filter used to fetch state
|
||||
from the database.
|
||||
Returns:
|
||||
Deferred[dict[int, dict[tuple[str, str], str]]]:
|
||||
dict of state_group_id -> (dict of (type, state_key) -> event id)
|
||||
Deferred[Dict[int, StateMap[str]]]: Dict of state group to state map.
|
||||
"""
|
||||
|
||||
member_filter, non_member_filter = state_filter.get_member_split()
|
||||
|
|
@ -268,24 +272,24 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
|
||||
return state
|
||||
|
||||
def _get_state_for_groups_using_cache(self, groups, cache, state_filter):
|
||||
def _get_state_for_groups_using_cache(
|
||||
self, groups: Iterable[int], cache: DictionaryCache, state_filter: StateFilter
|
||||
) -> Tuple[Dict[int, StateMap[str]], Set[int]]:
|
||||
"""Gets the state at each of a list of state groups, optionally
|
||||
filtering by type/state_key, querying from a specific cache.
|
||||
|
||||
Args:
|
||||
groups (iterable[int]): list of state groups for which we want
|
||||
to get the state.
|
||||
cache (DictionaryCache): the cache of group ids to state dicts which
|
||||
we will pass through - either the normal state cache or the specific
|
||||
members state cache.
|
||||
state_filter (StateFilter): The state filter used to fetch state
|
||||
from the database.
|
||||
groups: list of state groups for which we want to get the state.
|
||||
cache: the cache of group ids to state dicts which
|
||||
we will pass through - either the normal state cache or the
|
||||
specific members state cache.
|
||||
state_filter: The state filter used to fetch state from the
|
||||
database.
|
||||
|
||||
Returns:
|
||||
tuple[dict[int, dict[tuple[str, str], str]], set[int]]: Tuple of
|
||||
dict of state_group_id -> (dict of (type, state_key) -> event id)
|
||||
of entries in the cache, and the state group ids either missing
|
||||
from the cache or incomplete.
|
||||
Tuple of dict of state_group_id to state map of entries in the
|
||||
cache, and the state group ids either missing from the cache or
|
||||
incomplete.
|
||||
"""
|
||||
results = {}
|
||||
incomplete_groups = set()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue