Revert "TEMPORARY Add more Measure blocks"

This reverts commit adfa0fded3.
This commit is contained in:
Olivier Wilkinson (reivilibre) 2023-10-16 18:24:45 +01:00
parent adfa0fded3
commit 1e1cf4bb9d

View file

@ -124,7 +124,7 @@ async def resolve_events_with_store(
# Also fetch all auth events that appear in only some of the state sets' # Also fetch all auth events that appear in only some of the state sets'
# auth chains. # auth chains.
auth_diff = await _get_auth_chain_difference( auth_diff = await _get_auth_chain_difference(
room_id, state_sets, event_map, state_res_store, clock room_id, state_sets, event_map, state_res_store
) )
with Measure(clock, "rei_state_res:rews2_b"): # TODO temporary (rei) with Measure(clock, "rei_state_res:rews2_b"): # TODO temporary (rei)
@ -284,7 +284,6 @@ async def _get_auth_chain_difference(
state_sets: Sequence[StateMap[str]], state_sets: Sequence[StateMap[str]],
unpersisted_events: Dict[str, EventBase], unpersisted_events: Dict[str, EventBase],
state_res_store: StateResolutionStore, state_res_store: StateResolutionStore,
clock: Clock,
) -> Set[str]: ) -> Set[str]:
"""Compare the auth chains of each state set and return the set of events """Compare the auth chains of each state set and return the set of events
that only appear in some, but not all of the auth chains. that only appear in some, but not all of the auth chains.
@ -316,82 +315,77 @@ async def _get_auth_chain_difference(
# event IDs if they appear in the `unpersisted_events`. This is the intersection of # event IDs if they appear in the `unpersisted_events`. This is the intersection of
# the event's auth chain with the events in `unpersisted_events` *plus* their # the event's auth chain with the events in `unpersisted_events` *plus* their
# auth event IDs. # auth event IDs.
with Measure(clock, "rei_state_res:rews2_a1"): # TODO temporary (rei) events_to_auth_chain: Dict[str, Set[str]] = {}
events_to_auth_chain: Dict[str, Set[str]] = {} for event in unpersisted_events.values():
for event in unpersisted_events.values(): chain = {event.event_id}
chain = {event.event_id} events_to_auth_chain[event.event_id] = chain
events_to_auth_chain[event.event_id] = chain
to_search = [event] to_search = [event]
while to_search: while to_search:
for auth_id in to_search.pop().auth_event_ids(): for auth_id in to_search.pop().auth_event_ids():
chain.add(auth_id) chain.add(auth_id)
auth_event = unpersisted_events.get(auth_id) auth_event = unpersisted_events.get(auth_id)
if auth_event: if auth_event:
to_search.append(auth_event) to_search.append(auth_event)
# We now 1) calculate the auth chain difference for the unpersisted events # We now 1) calculate the auth chain difference for the unpersisted events
# and 2) work out the state sets to pass to the store. # and 2) work out the state sets to pass to the store.
# #
# Note: If there are no `unpersisted_events` (which is the common case), we can do a # Note: If there are no `unpersisted_events` (which is the common case), we can do a
# much simpler calculation. # much simpler calculation.
with Measure(clock, "rei_state_res:rews2_a2"): # TODO temporary (rei) if unpersisted_events:
if unpersisted_events: # The list of state sets to pass to the store, where each state set is a set
# The list of state sets to pass to the store, where each state set is a set # of the event ids making up the state. This is similar to `state_sets`,
# of the event ids making up the state. This is similar to `state_sets`, # except that (a) we only have event ids, not the complete
# except that (a) we only have event ids, not the complete # ((type, state_key)->event_id) mappings; and (b) we have stripped out
# ((type, state_key)->event_id) mappings; and (b) we have stripped out # unpersisted events and replaced them with the persisted events in
# unpersisted events and replaced them with the persisted events in # their auth chain.
# their auth chain. state_sets_ids: List[Set[str]] = []
state_sets_ids: List[Set[str]] = []
# For each state set, the unpersisted event IDs reachable (by their auth # For each state set, the unpersisted event IDs reachable (by their auth
# chain) from the events in that set. # chain) from the events in that set.
unpersisted_set_ids: List[Set[str]] = [] unpersisted_set_ids: List[Set[str]] = []
for state_set in state_sets: for state_set in state_sets:
set_ids: Set[str] = set() set_ids: Set[str] = set()
state_sets_ids.append(set_ids) state_sets_ids.append(set_ids)
unpersisted_ids: Set[str] = set() unpersisted_ids: Set[str] = set()
unpersisted_set_ids.append(unpersisted_ids) unpersisted_set_ids.append(unpersisted_ids)
for event_id in state_set.values(): for event_id in state_set.values():
event_chain = events_to_auth_chain.get(event_id) event_chain = events_to_auth_chain.get(event_id)
if event_chain is not None: if event_chain is not None:
# We have an unpersisted event. We add all the auth # We have an unpersisted event. We add all the auth
# events that it references which are also unpersisted. # events that it references which are also unpersisted.
set_ids.update( set_ids.update(
e for e in event_chain if e not in unpersisted_events e for e in event_chain if e not in unpersisted_events
) )
# We also add the full chain of unpersisted event IDs # We also add the full chain of unpersisted event IDs
# referenced by this state set, so that we can work out the # referenced by this state set, so that we can work out the
# auth chain difference of the unpersisted events. # auth chain difference of the unpersisted events.
unpersisted_ids.update( unpersisted_ids.update(
e for e in event_chain if e in unpersisted_events e for e in event_chain if e in unpersisted_events
) )
else: else:
set_ids.add(event_id) set_ids.add(event_id)
# The auth chain difference of the unpersisted events of the state sets # The auth chain difference of the unpersisted events of the state sets
# is calculated by taking the difference between the union and # is calculated by taking the difference between the union and
# intersections. # intersections.
union = unpersisted_set_ids[0].union(*unpersisted_set_ids[1:]) union = unpersisted_set_ids[0].union(*unpersisted_set_ids[1:])
intersection = unpersisted_set_ids[0].intersection(*unpersisted_set_ids[1:]) intersection = unpersisted_set_ids[0].intersection(*unpersisted_set_ids[1:])
auth_difference_unpersisted_part: StrCollection = union - intersection auth_difference_unpersisted_part: StrCollection = union - intersection
else: else:
auth_difference_unpersisted_part = () auth_difference_unpersisted_part = ()
state_sets_ids = [set(state_set.values()) for state_set in state_sets] state_sets_ids = [set(state_set.values()) for state_set in state_sets]
with Measure(clock, "rei_state_res:rews2_a3"): # TODO temporary (rei) difference = await state_res_store.get_auth_chain_difference(
difference = await state_res_store.get_auth_chain_difference( room_id, state_sets_ids
room_id, state_sets_ids )
) difference.update(auth_difference_unpersisted_part)
with Measure(clock, "rei_state_res:rews2_a4"): # TODO temporary (rei)
difference.update(auth_difference_unpersisted_part)
return difference return difference