summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorShay <hillerys@element.io>2023-03-07 13:54:39 -0800
committerGitHub <noreply@github.com>2023-03-07 13:54:39 -0800
commita368d30c1cfe7457fca4fcdd03ae481ba65a226c (patch)
tree9b7e69974604f0d7f73ef88617bfbfe8e1d8db33 /synapse/handlers
parentStabilize support for MSC3873: disambuguated event push keys. (#15190) (diff)
downloadsynapse-a368d30c1cfe7457fca4fcdd03ae481ba65a226c.tar.xz
More speedups/fixes to creating batched events (#15195)
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/event_auth.py13
-rw-r--r--synapse/handlers/room.py4
2 files changed, 14 insertions, 3 deletions
diff --git a/synapse/handlers/event_auth.py b/synapse/handlers/event_auth.py
index c508861b6a..0db0bd7304 100644
--- a/synapse/handlers/event_auth.py
+++ b/synapse/handlers/event_auth.py
@@ -63,9 +63,18 @@ class EventAuthHandler:
             self._store, event, batched_auth_events
         )
         auth_event_ids = event.auth_event_ids()
-        auth_events_by_id = await self._store.get_events(auth_event_ids)
+
         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())
 
     def compute_auth_events(
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index b1784638f4..32451670f3 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -1123,7 +1123,9 @@ class RoomCreationHandler:
                 event_dict,
                 prev_event_ids=prev_event,
                 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,
             )