@@ -1103,19 +1103,26 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
1103
1103
txn , room_id , user_id , stream_ordering , old_rotate_stream_ordering
1104
1104
)
1105
1105
1106
+ # First ensure that the existing rows have an updated thread_id field.
1107
+ self .db_pool .simple_update_txn (
1108
+ txn ,
1109
+ table = "event_push_summary" ,
1110
+ keyvalues = {"room_id" : room_id , "user_id" : user_id , "thread_id" : None },
1111
+ updatevalues = {"thread_id" : "main" },
1112
+ )
1113
+
1106
1114
# Replace the previous summary with the new counts.
1107
1115
#
1108
1116
# TODO(threads): Upsert per-thread instead of setting them all to main.
1109
1117
self .db_pool .simple_upsert_txn (
1110
1118
txn ,
1111
1119
table = "event_push_summary" ,
1112
- keyvalues = {"room_id" : room_id , "user_id" : user_id },
1120
+ keyvalues = {"room_id" : room_id , "user_id" : user_id , "thread_id" : "main" },
1113
1121
values = {
1114
1122
"notif_count" : notif_count ,
1115
1123
"unread_count" : unread_count ,
1116
1124
"stream_ordering" : old_rotate_stream_ordering ,
1117
1125
"last_receipt_stream_ordering" : stream_ordering ,
1118
- "thread_id" : "main" ,
1119
1126
},
1120
1127
)
1121
1128
@@ -1264,20 +1271,25 @@ def _rotate_notifs_before_txn(
1264
1271
1265
1272
logger .info ("Rotating notifications, handling %d rows" , len (summaries ))
1266
1273
1274
+ # Ensure that any updated threads have an updated thread_id.
1275
+ self .db_pool .simple_update_many_txn (
1276
+ txn ,
1277
+ table = "event_push_summary" ,
1278
+ key_names = ("user_id" , "room_id" , "thread_id" ),
1279
+ key_values = [(user_id , room_id , None ) for user_id , room_id in summaries ],
1280
+ value_names = ("thread_id" ,),
1281
+ value_values = [("main" ,) for _ in summaries ],
1282
+ )
1283
+
1267
1284
# TODO(threads): Update on a per-thread basis.
1268
1285
self .db_pool .simple_upsert_many_txn (
1269
1286
txn ,
1270
1287
table = "event_push_summary" ,
1271
- key_names = ("user_id" , "room_id" ),
1272
- key_values = [(user_id , room_id ) for user_id , room_id in summaries ],
1273
- value_names = ("notif_count" , "unread_count" , "stream_ordering" , "thread_id" ),
1288
+ key_names = ("user_id" , "room_id" , "thread_id" ),
1289
+ key_values = [(user_id , room_id , "main" ) for user_id , room_id in summaries ],
1290
+ value_names = ("notif_count" , "unread_count" , "stream_ordering" ),
1274
1291
value_values = [
1275
- (
1276
- summary .notif_count ,
1277
- summary .unread_count ,
1278
- summary .stream_ordering ,
1279
- "main" ,
1280
- )
1292
+ (summary .notif_count , summary .unread_count , summary .stream_ordering )
1281
1293
for summary in summaries .values ()
1282
1294
],
1283
1295
)
0 commit comments