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

Commit

Permalink
Speed up inserting event_push_actions_staging. (#13634)
Browse files Browse the repository at this point in the history
By using `execute_values` instead of `execute_batch`.
  • Loading branch information
clokep authored Aug 30, 2022
1 parent 682dfcf commit 20df96a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/13634.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of sending messages in rooms with thousands of local users.
28 changes: 8 additions & 20 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,26 +700,14 @@ def _gen_entry(
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:
Expand Down

0 comments on commit 20df96a

Please sign in to comment.