Fix remote receipts for events we don't have (#17096)

Introduced in #17032
This commit is contained in:
Erik Johnston 2024-04-17 16:08:40 +01:00 committed by GitHub
parent c8e0bed426
commit 803f05f60c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

1
changelog.d/17096.misc Normal file
View File

@ -0,0 +1 @@
Use new receipts column to optimise receipt and push action SQL queries. Contributed by Nick @ Beeper (@fizzadar).

View File

@ -734,9 +734,13 @@ class ReceiptsWorkerStore(SQLBaseStore):
thread_clause = "r.thread_id = ?" thread_clause = "r.thread_id = ?"
thread_args = (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""" sql = f"""
SELECT r.event_stream_ordering, r.event_id FROM receipts_linearized AS r 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( txn.execute(
sql, sql,