diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py index 5e85c5c40d9c..f0ca6473ff9a 100644 --- a/synapse/storage/databases/state/store.py +++ b/synapse/storage/databases/state/store.py @@ -176,7 +176,7 @@ def _get_state_group_delta_txn(txn: LoggingTransaction) -> _GetStateGroupDelta: ) 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 @@ async def _get_state_for_groups( if not incomplete_groups: return state - cache_sequence_nm = self._state_group_cache.sequence - cache_sequence_m = self._state_group_members_cache.sequence - - # 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 - ) + deferred_requests = [] + for group in incomplete_groups: + deferred_requests.append( + make_deferred_yieldable( + self._get_state_for_group_using_inflight_cache(group, state_filter) + ) + ) - # 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, + # ostd suspicious log context rules + results_from_requests = await make_deferred_yieldable( + defer.gatherResults( + deferred_requests, consumeErrors=False + ) # ostd consumeErrors?? ) - # 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