@@ -23,13 +23,25 @@ UPDATE event_push_actions_staging SET thread_id = 'main' WHERE thread_id IS NULL
23
23
UPDATE event_push_actions SET thread_id = ' main' WHERE thread_id IS NULL ;
24
24
25
25
-- Empirically we can end up with entries in the push summary table with both a
26
- -- `NULL` and `main` thread ID, which causes the update below to fail. We fudge
26
+ -- `NULL` and `main` thread ID, which causes the insert below to fail. We fudge
27
27
-- this by deleting any `NULL` rows that have a corresponding `main`.
28
28
DELETE FROM event_push_summary AS a WHERE thread_id IS NULL AND EXISTS (
29
29
SELECT 1 FROM event_push_summary AS b
30
30
WHERE b .thread_id = ' main' AND a .user_id = b .user_id AND a .room_id = b .room_id
31
31
);
32
- UPDATE event_push_summary SET thread_id = ' main' WHERE thread_id IS NULL ;
32
+ -- Copy the NULL threads to have a 'main' thread ID.
33
+ --
34
+ -- Note: Some people seem to have duplicate rows with a `NULL` thread ID, in
35
+ -- which case we just fudge it with using MAX of the values. The counts *may* be
36
+ -- wrong for such rooms, but a) its an edge case, and b) they'll be fixed when
37
+ -- the user reads the room.
38
+ INSERT INTO event_push_summary (user_id, room_id, notif_count, stream_ordering, unread_count, last_receipt_stream_ordering, thread_id)
39
+ SELECT user_id, room_id, MAX (notif_count), MAX (stream_ordering), MAX (unread_count), MAX (last_receipt_stream_ordering), ' main'
40
+ FROM event_push_summary
41
+ WHERE thread_id IS NULL
42
+ GROUP BY user_id, room_id, thread_id;
43
+
44
+ DELETE FROM event_push_summary AS a WHERE thread_id IS NULL ;
33
45
34
46
-- Drop the background updates to calculate the indexes used to find null thread_ids.
35
47
DELETE FROM background_updates WHERE update_name = ' event_push_actions_thread_id_null' ;
0 commit comments