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

Commit

Permalink
Handle remote receipts better
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jun 27, 2022
1 parent 22bd551 commit 3fb73c3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,16 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
rows = txn.fetchall()

if not rows:
# We always update `event_push_summary_last_receipt_stream_id` to
# ensure that we don't rescan the same receipts for remote users.
#
# This requires repeatable read to be safe.
txn.execute(
"""
UPDATE event_push_summary_last_receipt_stream_id
SET stream_id = (SELECT COALESCE(MAX(stream_id), 0) FROM receipts_linearized)
"""
)
return True

# For each new read receipt we delete push actions from before it and
Expand Down Expand Up @@ -908,13 +918,15 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
},
)

last_stream_id = rows[-1][0]

self.db_pool.simple_update_one_txn(
txn,
table="event_push_summary_last_receipt_stream_id",
keyvalues={},
updatevalues={"stream_id": last_stream_id},
# We always update `event_push_summary_last_receipt_stream_id` to
# ensure that we don't rescan the same receipts for remote users.
#
# This requires repeatable read to be safe.
txn.execute(
"""
UPDATE event_push_summary_last_receipt_stream_id
SET stream_id = (SELECT COALESCE(MAX(stream_id), 0) FROM receipts_linearized)
"""
)

return len(rows) < limit
Expand Down

0 comments on commit 3fb73c3

Please sign in to comment.