-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Speed up inserting event_push_actions_staging
#13634
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
| ], | ||
|
Comment on lines
+706
to
+709
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method must take a (I think this is actually a bug in the old code, but now is caught by type hints.)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I don't think so, as previously we created the generator inside the transaction, and its the entire transaction that gets retried (rather than just the individual queries)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good call. Well now that we do it outside we need a list! |
||
| desc="add_push_actions_to_staging", | ||
| ) | ||
|
|
||
| async def remove_push_actions_from_staging(self, event_id: str) -> None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is out of date due to a combination of #11560 and #11742.