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

Commit

Permalink
Fix rotating existing notifications in push summary (#14138)
Browse files Browse the repository at this point in the history
Broke by #14045. Fixes #14120.

Introduced in v1.69.0rc2.
  • Loading branch information
erikjohnston committed Oct 11, 2022
1 parent 422cff7 commit 02086e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/14138.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix error in background update when rotating existing notifications. Introduced in v1.69.0rc2.
20 changes: 15 additions & 5 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,11 +1104,13 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
)

# First ensure that the existing rows have an updated thread_id field.
self.db_pool.simple_update_txn(
txn,
table="event_push_summary",
keyvalues={"room_id": room_id, "user_id": user_id, "thread_id": None},
updatevalues={"thread_id": "main"},
txn.execute(
"""
UPDATE event_push_summary
SET thread_id = ?
WHERE room_id = ? AND user_id = ? AND thread_id is NULL
""",
("main", room_id, user_id),
)

# Replace the previous summary with the new counts.
Expand Down Expand Up @@ -1272,6 +1274,14 @@ def _rotate_notifs_before_txn(
logger.info("Rotating notifications, handling %d rows", len(summaries))

# 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(
txn,
table="event_push_summary",
Expand Down

0 comments on commit 02086e1

Please sign in to comment.