Fix rotating existing notifications in push summary (#14138)

Broke by #14045. Fixes #14120.

Introduced in v1.69.0rc2.
This commit is contained in:
Erik Johnston 2022-10-11 16:13:32 +01:00 committed by GitHub
parent 422cff7df6
commit 02086e1da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

1
changelog.d/14138.bugfix Normal file
View File

@ -0,0 +1 @@
Fix error in background update when rotating existing notifications. Introduced in v1.69.0rc2.

View File

@ -1104,11 +1104,13 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
) )
# First ensure that the existing rows have an updated thread_id field. # First ensure that the existing rows have an updated thread_id field.
self.db_pool.simple_update_txn( txn.execute(
txn, """
table="event_push_summary", UPDATE event_push_summary
keyvalues={"room_id": room_id, "user_id": user_id, "thread_id": None}, SET thread_id = ?
updatevalues={"thread_id": "main"}, WHERE room_id = ? AND user_id = ? AND thread_id is NULL
""",
("main", room_id, user_id),
) )
# Replace the previous summary with the new counts. # Replace the previous summary with the new counts.
@ -1272,6 +1274,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
logger.info("Rotating notifications, handling %d rows", len(summaries)) logger.info("Rotating notifications, handling %d rows", len(summaries))
# Ensure that any updated threads have an updated thread_id. # Ensure that any updated threads have an updated thread_id.
txn.execute_batch(
"""
UPDATE event_push_summary
SET thread_id = ?
WHERE room_id = ? AND user_id = ? AND thread_id is NULL
""",
[("main", room_id, user_id) for user_id, room_id in summaries],
)
self.db_pool.simple_update_many_txn( self.db_pool.simple_update_many_txn(
txn, txn,
table="event_push_summary", table="event_push_summary",