Use the in-flight caches for _get_state_for_groups
This commit is contained in:
parent
247f558c1c
commit
7dcdab407c
|
@ -176,7 +176,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
)
|
||||
|
||||
async def _get_state_groups_from_groups(
|
||||
self, groups: List[int], state_filter: StateFilter
|
||||
self, groups: Sequence[int], state_filter: StateFilter
|
||||
) -> Dict[int, StateMap[str]]:
|
||||
"""Returns the state groups for a given set of groups from the
|
||||
database, filtering on types of state events.
|
||||
|
@ -433,30 +433,23 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
if not incomplete_groups:
|
||||
return state
|
||||
|
||||
cache_sequence_nm = self._state_group_cache.sequence
|
||||
cache_sequence_m = self._state_group_members_cache.sequence
|
||||
deferred_requests = []
|
||||
for group in incomplete_groups:
|
||||
deferred_requests.append(
|
||||
make_deferred_yieldable(
|
||||
self._get_state_for_group_using_inflight_cache(group, state_filter)
|
||||
)
|
||||
)
|
||||
|
||||
# Help the cache hit ratio by expanding the filter a bit
|
||||
db_state_filter = state_filter.return_expanded()
|
||||
|
||||
group_to_state_dict = await self._get_state_groups_from_groups(
|
||||
list(incomplete_groups), state_filter=db_state_filter
|
||||
# ostd suspicious log context rules
|
||||
results_from_requests = await make_deferred_yieldable(
|
||||
defer.gatherResults(
|
||||
deferred_requests, consumeErrors=False
|
||||
) # ostd consumeErrors??
|
||||
)
|
||||
|
||||
# Now lets update the caches
|
||||
self._insert_into_cache(
|
||||
group_to_state_dict,
|
||||
db_state_filter,
|
||||
cache_seq_num_members=cache_sequence_m,
|
||||
cache_seq_num_non_members=cache_sequence_nm,
|
||||
)
|
||||
|
||||
# And finally update the result dict, by filtering out any extra
|
||||
# stuff we pulled out of the database.
|
||||
for group, group_state_dict in group_to_state_dict.items():
|
||||
# We just replace any existing entries, as we will have loaded
|
||||
# everything we need from the database anyway.
|
||||
state[group] = state_filter.filter_state(group_state_dict)
|
||||
for group, group_result in zip(incomplete_groups, results_from_requests):
|
||||
state[group] = group_result
|
||||
|
||||
return state
|
||||
|
||||
|
|
Loading…
Reference in a new issue