From bc5dc69d8d7b004d4062d53a912be11b229e1c57 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 15 Apr 2024 12:13:53 +0100 Subject: [PATCH 1/2] Fix remote receipts for events we don't have Introduced in #17032 --- synapse/storage/databases/main/receipts.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index 9660fc46997..13387a38396 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -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, From 5104594a86b4c2058839618ae5fc3b7cb1a451a7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 15 Apr 2024 12:14:41 +0100 Subject: [PATCH 2/2] Newsfile --- changelog.d/17096.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17096.misc diff --git a/changelog.d/17096.misc b/changelog.d/17096.misc new file mode 100644 index 00000000000..b03f6f42e5f --- /dev/null +++ b/changelog.d/17096.misc @@ -0,0 +1 @@ +Use new receipts column to optimise receipt and push action SQL queries. Contributed by Nick @ Beeper (@fizzadar).