Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3d9f82e

Browse files
authored
Use an upsert for receipts_graph. (#13752)
Instead of a delete, then insert. This was previously done for `receipts_linearized` in 2dc430d (#7607).
1 parent c85c5ac commit 3d9f82e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

changelog.d/13752.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
User an additional database query when persisting receipts.

synapse/storage/databases/main/receipts.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,25 +812,21 @@ def _insert_graph_receipt_txn(
812812
# FIXME: This shouldn't invalidate the whole cache
813813
txn.call_after(self._get_linearized_receipts_for_room.invalidate, (room_id,))
814814

815-
self.db_pool.simple_delete_txn(
815+
self.db_pool.simple_upsert_txn(
816816
txn,
817817
table="receipts_graph",
818818
keyvalues={
819819
"room_id": room_id,
820820
"receipt_type": receipt_type,
821821
"user_id": user_id,
822822
},
823-
)
824-
self.db_pool.simple_insert_txn(
825-
txn,
826-
table="receipts_graph",
827823
values={
828-
"room_id": room_id,
829-
"receipt_type": receipt_type,
830-
"user_id": user_id,
831824
"event_ids": json_encoder.encode(event_ids),
832825
"data": json_encoder.encode(data),
833826
},
827+
# receipts_graph has a unique constraint on
828+
# (user_id, room_id, receipt_type), so no need to lock
829+
lock=False,
834830
)
835831

836832

0 commit comments

Comments
 (0)