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

Commit

Permalink
Use upsert when inserting read receipts (#7607)
Browse files Browse the repository at this point in the history
Fixes #7469

Signed-off-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  • Loading branch information
ilmari authored Jun 1, 2020
1 parent 91a7c5f commit 2dc430d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/7607.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix duplicate key violation when persisting read markers.
13 changes: 4 additions & 9 deletions synapse/storage/data_stores/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,27 +391,22 @@ def insert_linearized_receipt_txn(
(user_id, room_id, receipt_type),
)

self.db.simple_delete_txn(
self.db.simple_upsert_txn(
txn,
table="receipts_linearized",
keyvalues={
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id,
},
)

self.db.simple_insert_txn(
txn,
table="receipts_linearized",
values={
"stream_id": stream_id,
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id,
"event_id": event_id,
"data": json.dumps(data),
},
# receipts_linearized has a unique constraint on
# (user_id, room_id, receipt_type), so no need to lock
lock=False,
)

if receipt_type == "m.read" and stream_ordering is not None:
Expand Down

0 comments on commit 2dc430d

Please sign in to comment.