Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Use the in-flight caches for _get_state_for_groups
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Sep 21, 2021
1 parent 247f558 commit 7dcdab4
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions synapse/storage/databases/state/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7dcdab4

Please sign in to comment.