diff options
author | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-09-21 16:48:02 +0100 |
---|---|---|
committer | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-09-21 17:14:18 +0100 |
commit | 7dcdab407ca61371b9c80a94cdf7035bdf0bfad1 (patch) | |
tree | 87577673326b8c9c7b1bfefa633b7c7bc5ea5ea3 /synapse | |
parent | Add method to get 1 state group, both using and updating in-flight cache (diff) | |
download | synapse-7dcdab407ca61371b9c80a94cdf7035bdf0bfad1.tar.xz |
Use the in-flight caches for `_get_state_for_groups`
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/databases/state/store.py | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py index 5e85c5c40d..f0ca6473ff 100644 --- a/synapse/storage/databases/state/store.py +++ b/synapse/storage/databases/state/store.py @@ -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 - - # 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 |