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

Pull out less state when handling gaps mk2 #12852

Merged
merged 15 commits into from
May 26, 2022
Merged
20 changes: 16 additions & 4 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,12 +1022,24 @@ async def create_new_client_event(
#
# TODO(faster_joins): figure out how this works, and make sure that the
# old state is complete.
old_state = await self.store.get_events_as_list(state_event_ids)
metadata = await self.store.get_metadata_for_events(state_event_ids)

state_map = {}
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
for state_id in state_event_ids:
data = metadata.get(state_id)
if data is None:
raise Exception("State event not persisted %s", state_id)
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add some more comments, and/or improve the exception message here. What exactly does it mean? Somebody is trying to send an insertion event which refers to a state event which we haven't (yet?) seen? Is there a mechanism to pull said event which has failed, or is this a client-side error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added a comment to try and address those questions, hopefully it makes sense now?

edcd824#diff-3d4a81fcc5b115c649ae67aaba0dd4dd0c5827bb001dfcb90b00ffb1605d518eR1038-R1048


if data.state_key is None:
raise Exception(
"Trying to set non-state event as state: %s", state_id
)
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

state_map[(data.event_type, data.state_key)] = state_id

context = await self.state.compute_event_context(
event,
state_ids_before_event={
(e.type, e.state_key): e.event_id for e in old_state
},
state_ids_before_event=state_map,
)
else:
context = await self.state.compute_event_context(event)
Expand Down