Skip to content

Commit 08b9f34

Browse files
ilmariphil-flex
authored andcommitted
Use upsert when inserting read receipts (matrix-org#7607)
Fixes matrix-org#7469 Signed-off-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
1 parent bc34cd9 commit 08b9f34

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

changelog.d/7607.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix duplicate key violation when persisting read markers.

synapse/storage/data_stores/main/receipts.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,27 +391,22 @@ def insert_linearized_receipt_txn(
391391
(user_id, room_id, receipt_type),
392392
)
393393

394-
self.db.simple_delete_txn(
394+
self.db.simple_upsert_txn(
395395
txn,
396396
table="receipts_linearized",
397397
keyvalues={
398398
"room_id": room_id,
399399
"receipt_type": receipt_type,
400400
"user_id": user_id,
401401
},
402-
)
403-
404-
self.db.simple_insert_txn(
405-
txn,
406-
table="receipts_linearized",
407402
values={
408403
"stream_id": stream_id,
409-
"room_id": room_id,
410-
"receipt_type": receipt_type,
411-
"user_id": user_id,
412404
"event_id": event_id,
413405
"data": json.dumps(data),
414406
},
407+
# receipts_linearized has a unique constraint on
408+
# (user_id, room_id, receipt_type), so no need to lock
409+
lock=False,
415410
)
416411

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

0 commit comments

Comments
 (0)