Skip to content

Commit 803f05f

Browse files
authored
Fix remote receipts for events we don't have (#17096)
Introduced in #17032
1 parent c8e0bed commit 803f05f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

changelog.d/17096.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use new receipts column to optimise receipt and push action SQL queries. Contributed by Nick @ Beeper (@fizzadar).

synapse/storage/databases/main/receipts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,13 @@ def _insert_linearized_receipt_txn(
734734
thread_clause = "r.thread_id = ?"
735735
thread_args = (thread_id,)
736736

737+
# If the receipt doesn't have a stream ordering it is because we
738+
# don't have the associated event, and so must be a remote receipt.
739+
# Hence it's safe to just allow new receipts to clobber it.
737740
sql = f"""
738741
SELECT r.event_stream_ordering, r.event_id FROM receipts_linearized AS r
739-
WHERE r.room_id = ? AND r.receipt_type = ? AND r.user_id = ? AND {thread_clause}
742+
WHERE r.room_id = ? AND r.receipt_type = ? AND r.user_id = ?
743+
AND r.event_stream_ordering IS NOT NULL AND {thread_clause}
740744
"""
741745
txn.execute(
742746
sql,

0 commit comments

Comments
 (0)