Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 20df96a

Browse files
authored
Speed up inserting event_push_actions_staging. (#13634)
By using `execute_values` instead of `execute_batch`.
1 parent 682dfcf commit 20df96a

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

changelog.d/13634.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve performance of sending messages in rooms with thousands of local users.

synapse/storage/databases/main/event_push_actions.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -700,26 +700,14 @@ def _gen_entry(
700700
int(count_as_unread), # unread column
701701
)
702702

703-
def _add_push_actions_to_staging_txn(txn: LoggingTransaction) -> None:
704-
# We don't use simple_insert_many here to avoid the overhead
705-
# of generating lists of dicts.
706-
707-
sql = """
708-
INSERT INTO event_push_actions_staging
709-
(event_id, user_id, actions, notif, highlight, unread)
710-
VALUES (?, ?, ?, ?, ?, ?)
711-
"""
712-
713-
txn.execute_batch(
714-
sql,
715-
(
716-
_gen_entry(user_id, actions)
717-
for user_id, actions in user_id_actions.items()
718-
),
719-
)
720-
721-
return await self.db_pool.runInteraction(
722-
"add_push_actions_to_staging", _add_push_actions_to_staging_txn
703+
await self.db_pool.simple_insert_many(
704+
"event_push_actions_staging",
705+
keys=("event_id", "user_id", "actions", "notif", "highlight", "unread"),
706+
values=[
707+
_gen_entry(user_id, actions)
708+
for user_id, actions in user_id_actions.items()
709+
],
710+
desc="add_push_actions_to_staging",
723711
)
724712

725713
async def remove_push_actions_from_staging(self, event_id: str) -> None:

0 commit comments

Comments
 (0)