mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 15:33:53 +01:00
Speed up inserting event_push_actions_staging
. (#13634)
By using `execute_values` instead of `execute_batch`.
This commit is contained in:
parent
682dfcfc0d
commit
20df96a7a7
2 changed files with 9 additions and 20 deletions
1
changelog.d/13634.feature
Normal file
1
changelog.d/13634.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Improve performance of sending messages in rooms with thousands of local users.
|
|
@ -700,26 +700,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
||||||
int(count_as_unread), # unread column
|
int(count_as_unread), # unread column
|
||||||
)
|
)
|
||||||
|
|
||||||
def _add_push_actions_to_staging_txn(txn: LoggingTransaction) -> None:
|
await self.db_pool.simple_insert_many(
|
||||||
# We don't use simple_insert_many here to avoid the overhead
|
"event_push_actions_staging",
|
||||||
# of generating lists of dicts.
|
keys=("event_id", "user_id", "actions", "notif", "highlight", "unread"),
|
||||||
|
values=[
|
||||||
sql = """
|
_gen_entry(user_id, actions)
|
||||||
INSERT INTO event_push_actions_staging
|
for user_id, actions in user_id_actions.items()
|
||||||
(event_id, user_id, actions, notif, highlight, unread)
|
],
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
desc="add_push_actions_to_staging",
|
||||||
"""
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def remove_push_actions_from_staging(self, event_id: str) -> None:
|
async def remove_push_actions_from_staging(self, event_id: str) -> None:
|
||||||
|
|
Loading…
Reference in a new issue