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

Commit

Permalink
Use an upsert for receipts_graph. (#13752)
Browse files Browse the repository at this point in the history
Instead of a delete, then insert.

This was previously done for `receipts_linearized` in
2dc430d (#7607).
  • Loading branch information
clokep authored Sep 9, 2022
1 parent c85c5ac commit 3d9f82e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/13752.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User an additional database query when persisting receipts.
12 changes: 4 additions & 8 deletions synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,25 +812,21 @@ def _insert_graph_receipt_txn(
# FIXME: This shouldn't invalidate the whole cache
txn.call_after(self._get_linearized_receipts_for_room.invalidate, (room_id,))

self.db_pool.simple_delete_txn(
self.db_pool.simple_upsert_txn(
txn,
table="receipts_graph",
keyvalues={
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id,
},
)
self.db_pool.simple_insert_txn(
txn,
table="receipts_graph",
values={
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id,
"event_ids": json_encoder.encode(event_ids),
"data": json_encoder.encode(data),
},
# receipts_graph has a unique constraint on
# (user_id, room_id, receipt_type), so no need to lock
lock=False,
)


Expand Down

0 comments on commit 3d9f82e

Please sign in to comment.