Skip to content
Snippets Groups Projects
Unverified Commit a368d30c authored by Shay's avatar Shay Committed by GitHub
Browse files

More speedups/fixes to creating batched events (#15195)

parent 20ed8c92
No related branches found
No related tags found
No related merge requests found
Improve performance of creating and authenticating events.
\ No newline at end of file
...@@ -168,13 +168,24 @@ async def check_state_independent_auth_rules( ...@@ -168,13 +168,24 @@ async def check_state_independent_auth_rules(
return return
# 2. Reject if event has auth_events that: ... # 2. Reject if event has auth_events that: ...
auth_events = await store.get_events(
event.auth_event_ids(),
redact_behaviour=EventRedactBehaviour.as_is,
allow_rejected=True,
)
if batched_auth_events: if batched_auth_events:
auth_events.update(batched_auth_events) # Copy the batched auth events to avoid mutating them.
auth_events = dict(batched_auth_events)
needed_auth_event_ids = set(event.auth_event_ids()) - batched_auth_events.keys()
if needed_auth_event_ids:
auth_events.update(
await store.get_events(
needed_auth_event_ids,
redact_behaviour=EventRedactBehaviour.as_is,
allow_rejected=True,
)
)
else:
auth_events = await store.get_events(
event.auth_event_ids(),
redact_behaviour=EventRedactBehaviour.as_is,
allow_rejected=True,
)
room_id = event.room_id room_id = event.room_id
auth_dict: MutableStateMap[str] = {} auth_dict: MutableStateMap[str] = {}
......
...@@ -293,6 +293,7 @@ class EventContext(UnpersistedEventContextBase): ...@@ -293,6 +293,7 @@ class EventContext(UnpersistedEventContextBase):
Maps a (type, state_key) to the event ID of the state event matching Maps a (type, state_key) to the event ID of the state event matching
this tuple. this tuple.
""" """
assert self.state_group_before_event is not None assert self.state_group_before_event is not None
return await self._storage.state.get_state_ids_for_group( return await self._storage.state.get_state_ids_for_group(
self.state_group_before_event, state_filter self.state_group_before_event, state_filter
......
...@@ -63,9 +63,18 @@ class EventAuthHandler: ...@@ -63,9 +63,18 @@ class EventAuthHandler:
self._store, event, batched_auth_events self._store, event, batched_auth_events
) )
auth_event_ids = event.auth_event_ids() auth_event_ids = event.auth_event_ids()
auth_events_by_id = await self._store.get_events(auth_event_ids)
if batched_auth_events: if batched_auth_events:
auth_events_by_id.update(batched_auth_events) # Copy the batched auth events to avoid mutating them.
auth_events_by_id = dict(batched_auth_events)
needed_auth_event_ids = set(auth_event_ids) - set(batched_auth_events)
if needed_auth_event_ids:
auth_events_by_id.update(
await self._store.get_events(needed_auth_event_ids)
)
else:
auth_events_by_id = await self._store.get_events(auth_event_ids)
check_state_dependent_auth_rules(event, auth_events_by_id.values()) check_state_dependent_auth_rules(event, auth_events_by_id.values())
def compute_auth_events( def compute_auth_events(
......
...@@ -1123,7 +1123,9 @@ class RoomCreationHandler: ...@@ -1123,7 +1123,9 @@ class RoomCreationHandler:
event_dict, event_dict,
prev_event_ids=prev_event, prev_event_ids=prev_event,
depth=depth, depth=depth,
state_map=state_map, # Take a copy to ensure each event gets a unique copy of
# state_map since it is modified below.
state_map=dict(state_map),
for_batch=for_batch, for_batch=for_batch,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment