diff options
author | Nick Mills-Barrett <nick@beeper.com> | 2023-05-18 19:37:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 14:37:31 -0400 |
commit | ad50510a06d035a674f0eeed5db5dd3060bc0b1c (patch) | |
tree | b2b8110f0d5e223a0bd28d5f4e4a8acac1e7dcd1 /synapse/handlers | |
parent | Update Mutual Rooms (MSC2666) implementation (#15621) (diff) | |
download | synapse-ad50510a06d035a674f0eeed5db5dd3060bc0b1c.tar.xz |
Handle missing previous read marker event. (#15464)
If the previous read marker is pointing to an event that no longer exists (e.g. due to retention) then assume that the newly given read marker is newer.
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/read_marker.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/synapse/handlers/read_marker.py b/synapse/handlers/read_marker.py index 6d35e61880..49a497a860 100644 --- a/synapse/handlers/read_marker.py +++ b/synapse/handlers/read_marker.py @@ -16,6 +16,7 @@ import logging from typing import TYPE_CHECKING from synapse.api.constants import ReceiptTypes +from synapse.api.errors import SynapseError from synapse.util.async_helpers import Linearizer if TYPE_CHECKING: @@ -47,12 +48,21 @@ class ReadMarkerHandler: ) should_update = True + # Get event ordering, this also ensures we know about the event + event_ordering = await self.store.get_event_ordering(event_id) if existing_read_marker: - # Only update if the new marker is ahead in the stream - should_update = await self.store.is_event_after( - event_id, existing_read_marker["event_id"] - ) + try: + old_event_ordering = await self.store.get_event_ordering( + existing_read_marker["event_id"] + ) + except SynapseError: + # Old event no longer exists, assume new is ahead. This may + # happen if the old event was removed due to retention. + pass + else: + # Only update if the new marker is ahead in the stream + should_update = event_ordering > old_event_ordering if should_update: content = {"event_id": event_id} |