Skip to content

Commit

Permalink
Fix remote receipts for events we don't have (#17096)
Browse files Browse the repository at this point in the history
Introduced in #17032
  • Loading branch information
erikjohnston authored Apr 17, 2024
1 parent c8e0bed commit 803f05f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/17096.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use new receipts column to optimise receipt and push action SQL queries. Contributed by Nick @ Beeper (@fizzadar).
6 changes: 5 additions & 1 deletion synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,13 @@ def _insert_linearized_receipt_txn(
thread_clause = "r.thread_id = ?"
thread_args = (thread_id,)

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

0 comments on commit 803f05f

Please sign in to comment.