summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2022-08-30 07:12:48 -0400
committerGitHub <noreply@github.com>2022-08-30 07:12:48 -0400
commit20df96a7a7e3d676b0beae12d0eeb1f1d668247e (patch)
treeaae97add68dca8779c791cff3cdf24feddd22abd
parentFix that user cannot `/forget` rooms after the last member has left (#13546) (diff)
downloadsynapse-20df96a7a7e3d676b0beae12d0eeb1f1d668247e.tar.xz
Speed up inserting `event_push_actions_staging`. (#13634)
By using `execute_values` instead of `execute_batch`.
-rw-r--r--changelog.d/13634.feature1
-rw-r--r--synapse/storage/databases/main/event_push_actions.py28
2 files changed, 9 insertions, 20 deletions
diff --git a/changelog.d/13634.feature b/changelog.d/13634.feature
new file mode 100644
index 0000000000..0a8827205d
--- /dev/null
+++ b/changelog.d/13634.feature
@@ -0,0 +1 @@
+Improve performance of sending messages in rooms with thousands of local users.
diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py
index 8dfa545c27..9f410d69de 100644
--- a/synapse/storage/databases/main/event_push_actions.py
+++ b/synapse/storage/databases/main/event_push_actions.py
@@ -700,26 +700,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
                 int(count_as_unread),  # unread column
             )
 
-        def _add_push_actions_to_staging_txn(txn: LoggingTransaction) -> None:
-            # We don't use simple_insert_many here to avoid the overhead
-            # of generating lists of dicts.
-
-            sql = """
-                INSERT INTO event_push_actions_staging
-                    (event_id, user_id, actions, notif, highlight, unread)
-                VALUES (?, ?, ?, ?, ?, ?)
-            """
-
-            txn.execute_batch(
-                sql,
-                (
-                    _gen_entry(user_id, actions)
-                    for user_id, actions in user_id_actions.items()
-                ),
-            )
-
-        return await self.db_pool.runInteraction(
-            "add_push_actions_to_staging", _add_push_actions_to_staging_txn
+        await self.db_pool.simple_insert_many(
+            "event_push_actions_staging",
+            keys=("event_id", "user_id", "actions", "notif", "highlight", "unread"),
+            values=[
+                _gen_entry(user_id, actions)
+                for user_id, actions in user_id_actions.items()
+            ],
+            desc="add_push_actions_to_staging",
         )
 
     async def remove_push_actions_from_staging(self, event_id: str) -> None: