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

Commit

Permalink
Speed up query
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jun 27, 2022
1 parent 5c88a5e commit a3c49e8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions synapse/storage/databases/main/event_push_actions.py
Expand Up @@ -836,10 +836,18 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:

limit = 100

min_stream_id = self.db_pool.simple_select_one_onecol_txn(
txn,
table="event_push_summary_last_receipt_stream_id",
keyvalues={},
retcol="stream_id",
)

sql = """
SELECT r.stream_id, r.room_id, r.user_id, e.stream_ordering
FROM receipts_linearized AS r, event_push_summary_last_receipt_stream_id AS eps, events AS e
WHERE r.stream_id > eps.stream_id AND r.event_id = e.event_id AND user_id LIKE ?
FROM receipts_linearized AS r
INNER JOIN events AS e USING (event_id)
WHERE r.stream_id > ? AND user_id LIKE ?
ORDER BY r.stream_id ASC
LIMIT ?
"""
Expand All @@ -849,6 +857,7 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
txn.execute(
sql,
(
min_stream_id,
user_filter,
limit,
),
Expand Down

0 comments on commit a3c49e8

Please sign in to comment.