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

Commit e3d4755

Browse files
authored
Fix backwards compatibility with upcoming threads schema changes. (#14045)
Ensure that the upsert will work properly by first updating any existing rows (in the same way that the background update to backfill data works).
1 parent 17bc4ec commit e3d4755

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

changelog.d/14045.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure Synapse v1.69 works with upcoming database changes in v1.70.

synapse/storage/databases/main/event_push_actions.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,19 +1103,26 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
11031103
txn, room_id, user_id, stream_ordering, old_rotate_stream_ordering
11041104
)
11051105

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+
11061114
# Replace the previous summary with the new counts.
11071115
#
11081116
# TODO(threads): Upsert per-thread instead of setting them all to main.
11091117
self.db_pool.simple_upsert_txn(
11101118
txn,
11111119
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"},
11131121
values={
11141122
"notif_count": notif_count,
11151123
"unread_count": unread_count,
11161124
"stream_ordering": old_rotate_stream_ordering,
11171125
"last_receipt_stream_ordering": stream_ordering,
1118-
"thread_id": "main",
11191126
},
11201127
)
11211128

@@ -1264,20 +1271,25 @@ def _rotate_notifs_before_txn(
12641271

12651272
logger.info("Rotating notifications, handling %d rows", len(summaries))
12661273

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+
12671284
# TODO(threads): Update on a per-thread basis.
12681285
self.db_pool.simple_upsert_many_txn(
12691286
txn,
12701287
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"),
12741291
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)
12811293
for summary in summaries.values()
12821294
],
12831295
)

0 commit comments

Comments
 (0)