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 3fb73c3 commit e8c71de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,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 @@ -858,6 +866,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 e8c71de

Please sign in to comment.