This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +33
-9
lines changed Expand file tree Collapse file tree 5 files changed +33
-9
lines changed Original file line number Diff line number Diff line change 1+ Improve performance of creating and authenticating events.
Original file line number Diff line number Diff line change @@ -168,13 +168,24 @@ async def check_state_independent_auth_rules(
168168 return
169169
170170 # 2. Reject if event has auth_events that: ...
171- auth_events = await store .get_events (
172- event .auth_event_ids (),
173- redact_behaviour = EventRedactBehaviour .as_is ,
174- allow_rejected = True ,
175- )
176171 if batched_auth_events :
177- auth_events .update (batched_auth_events )
172+ # Copy the batched auth events to avoid mutating them.
173+ auth_events = dict (batched_auth_events )
174+ needed_auth_event_ids = set (event .auth_event_ids ()) - batched_auth_events .keys ()
175+ if needed_auth_event_ids :
176+ auth_events .update (
177+ await store .get_events (
178+ needed_auth_event_ids ,
179+ redact_behaviour = EventRedactBehaviour .as_is ,
180+ allow_rejected = True ,
181+ )
182+ )
183+ else :
184+ auth_events = await store .get_events (
185+ event .auth_event_ids (),
186+ redact_behaviour = EventRedactBehaviour .as_is ,
187+ allow_rejected = True ,
188+ )
178189
179190 room_id = event .room_id
180191 auth_dict : MutableStateMap [str ] = {}
Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ async def get_prev_state_ids(
293293 Maps a (type, state_key) to the event ID of the state event matching
294294 this tuple.
295295 """
296+
296297 assert self .state_group_before_event is not None
297298 return await self ._storage .state .get_state_ids_for_group (
298299 self .state_group_before_event , state_filter
Original file line number Diff line number Diff line change @@ -63,9 +63,18 @@ async def check_auth_rules_from_context(
6363 self ._store , event , batched_auth_events
6464 )
6565 auth_event_ids = event .auth_event_ids ()
66- auth_events_by_id = await self . _store . get_events ( auth_event_ids )
66+
6767 if batched_auth_events :
68- auth_events_by_id .update (batched_auth_events )
68+ # Copy the batched auth events to avoid mutating them.
69+ auth_events_by_id = dict (batched_auth_events )
70+ needed_auth_event_ids = set (auth_event_ids ) - set (batched_auth_events )
71+ if needed_auth_event_ids :
72+ auth_events_by_id .update (
73+ await self ._store .get_events (needed_auth_event_ids )
74+ )
75+ else :
76+ auth_events_by_id = await self ._store .get_events (auth_event_ids )
77+
6978 check_state_dependent_auth_rules (event , auth_events_by_id .values ())
7079
7180 def compute_auth_events (
Original file line number Diff line number Diff line change @@ -1123,7 +1123,9 @@ async def create_event(
11231123 event_dict ,
11241124 prev_event_ids = prev_event ,
11251125 depth = depth ,
1126- state_map = state_map ,
1126+ # Take a copy to ensure each event gets a unique copy of
1127+ # state_map since it is modified below.
1128+ state_map = dict (state_map ),
11271129 for_batch = for_batch ,
11281130 )
11291131
You can’t perform that action at this time.
0 commit comments