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

Use upsert when inserting read receipts #7607

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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