@@ -118,38 +118,33 @@ async def get_receipts_for_room(
118
118
desc = "get_receipts_for_room" ,
119
119
)
120
120
121
- @cached (num_args = 3 )
121
+ @cached (num_args = 2 )
122
122
async def get_last_receipt_event_id_for_user (
123
- self , user_id : str , room_id : str , receipt_type : str
123
+ self , user_id : str , room_id : str
124
124
) -> Optional [str ]:
125
125
return await self .db_pool .simple_select_one_onecol (
126
126
table = "receipts_linearized" ,
127
127
keyvalues = {
128
128
"room_id" : room_id ,
129
- "receipt_type" : receipt_type ,
130
129
"user_id" : user_id ,
131
130
},
132
131
retcol = "event_id" ,
133
132
desc = "get_own_receipt_for_user" ,
134
133
allow_none = True ,
135
134
)
136
135
137
- @cached (num_args = 2 )
138
- async def get_receipts_for_user (
139
- self , user_id : str , receipt_type : str
140
- ) -> Dict [str , str ]:
136
+ @cached (num_args = 1 )
137
+ async def get_receipts_for_user (self , user_id : str ) -> Dict [str , str ]:
141
138
rows = await self .db_pool .simple_select_list (
142
139
table = "receipts_linearized" ,
143
- keyvalues = {"user_id" : user_id , "receipt_type" : receipt_type },
140
+ keyvalues = {"user_id" : user_id },
144
141
retcols = ("room_id" , "event_id" ),
145
142
desc = "get_receipts_for_user" ,
146
143
)
147
144
148
145
return {row ["room_id" ]: row ["event_id" ] for row in rows }
149
146
150
- async def get_receipts_for_user_with_orderings (
151
- self , user_id : str , receipt_type : str
152
- ) -> JsonDict :
147
+ async def get_receipts_for_user_with_orderings (self , user_id : str ) -> JsonDict :
153
148
def f (txn : LoggingTransaction ) -> List [Tuple [str , str , int , int ]]:
154
149
sql = (
155
150
"SELECT rl.room_id, rl.event_id,"
@@ -490,9 +485,7 @@ def invalidate_caches_for_receipt(
490
485
) -> None :
491
486
self .get_receipts_for_user .invalidate ((user_id , receipt_type ))
492
487
self ._get_linearized_receipts_for_room .invalidate ((room_id ,))
493
- self .get_last_receipt_event_id_for_user .invalidate (
494
- (user_id , room_id , receipt_type )
495
- )
488
+ self .get_last_receipt_event_id_for_user .invalidate ((user_id , room_id ))
496
489
self ._invalidate_get_users_with_receipts_in_room (room_id , receipt_type , user_id )
497
490
self .get_receipts_for_room .invalidate ((room_id , receipt_type ))
498
491
@@ -541,14 +534,20 @@ def insert_linearized_receipt_txn(
541
534
# have to compare orderings of existing receipts
542
535
if stream_ordering is not None :
543
536
sql = (
544
- "SELECT stream_ordering, event_id FROM events"
545
- " INNER JOIN receipts_linearized as r USING (event_id, room_id)"
546
- " WHERE r.room_id = ? AND r.receipt_type = ? AND r. user_id = ?"
537
+ "SELECT e. stream_ordering, e. event_id, r.receipt_type FROM events AS e "
538
+ " INNER JOIN receipts_linearized AS r USING (event_id, room_id)"
539
+ " WHERE r.room_id = ? AND r.user_id = ?"
547
540
)
548
- txn .execute (sql , (room_id , receipt_type , user_id ))
549
-
550
- for so , eid in txn :
551
- if int (so ) >= stream_ordering :
541
+ txn .execute (sql , (room_id , user_id ))
542
+
543
+ for so , eid , rt in txn :
544
+ if int (so ) >= stream_ordering and (
545
+ receipt_type == rt
546
+ or (
547
+ rt == ReceiptTypes .READ
548
+ and receipt_type == ReceiptTypes .READ_PRIVATE
549
+ )
550
+ ):
552
551
logger .debug (
553
552
"Ignoring new receipt for %s in favour of existing "
554
553
"one for later event %s" ,
@@ -583,7 +582,10 @@ def insert_linearized_receipt_txn(
583
582
lock = False ,
584
583
)
585
584
586
- if receipt_type == ReceiptTypes .READ and stream_ordering is not None :
585
+ if (
586
+ receipt_type in [ReceiptTypes .READ , ReceiptTypes .READ_PRIVATE ]
587
+ and stream_ordering is not None
588
+ ):
587
589
self ._remove_old_push_actions_before_txn (
588
590
txn , room_id = room_id , user_id = user_id , stream_ordering = stream_ordering
589
591
)
0 commit comments