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(
168
168
return
169
169
170
170
# 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
- )
176
171
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
+ )
178
189
179
190
room_id = event .room_id
180
191
auth_dict : MutableStateMap [str ] = {}
Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ async def get_prev_state_ids(
293
293
Maps a (type, state_key) to the event ID of the state event matching
294
294
this tuple.
295
295
"""
296
+
296
297
assert self .state_group_before_event is not None
297
298
return await self ._storage .state .get_state_ids_for_group (
298
299
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(
63
63
self ._store , event , batched_auth_events
64
64
)
65
65
auth_event_ids = event .auth_event_ids ()
66
- auth_events_by_id = await self . _store . get_events ( auth_event_ids )
66
+
67
67
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
+
69
78
check_state_dependent_auth_rules (event , auth_events_by_id .values ())
70
79
71
80
def compute_auth_events (
Original file line number Diff line number Diff line change @@ -1123,7 +1123,9 @@ async def create_event(
1123
1123
event_dict ,
1124
1124
prev_event_ids = prev_event ,
1125
1125
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 ),
1127
1129
for_batch = for_batch ,
1128
1130
)
1129
1131
You can’t perform that action at this time.
0 commit comments