summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2024-07-10 16:27:11 +0100
committerErik Johnston <erik@matrix.org>2024-07-10 16:27:11 +0100
commit91f627b9a7c1912f3de20e758dc7f940781382b5 (patch)
treef25b523b57d35107348cc39c01a9394cb4fdc14d /synapse/handlers
parentFIXUP (diff)
downloadsynapse-91f627b9a7c1912f3de20e758dc7f940781382b5.tar.xz
FIXUP
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/sliding_sync.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py
index 501578bd3a..a0493d33db 100644
--- a/synapse/handlers/sliding_sync.py
+++ b/synapse/handlers/sliding_sync.py
@@ -1023,6 +1023,7 @@ class SlidingSyncHandler:
         # Assemble a map of room ID to the `stream_ordering` of the last activity that the
         # user should see in the room (<= `to_token`)
         last_activity_in_room_map: Dict[str, int] = {}
+        to_fetch = []
         for room_id, room_for_user in sync_room_map.items():
             # If they are fully-joined to the room, let's find the latest activity
             # at/before the `to_token`.
@@ -1032,14 +1033,7 @@ class SlidingSyncHandler:
                     last_activity_in_room_map[room_id] = stream_pos
                     continue
 
-                stream = await self.store.get_rough_stream_ordering_for_room(room_id)
-
-                # If the room has no events at/before the `to_token`, this is probably a
-                # mistake in the code that generates the `sync_room_map` since that should
-                # only give us rooms that the user had membership in during the token range.
-                assert stream is not None
-
-                last_activity_in_room_map[room_id] = stream
+                to_fetch.append(room_id)
             else:
                 # Otherwise, if the user has left/been invited/knocked/been banned from
                 # a room, they shouldn't see anything past that point.
@@ -1050,6 +1044,10 @@ class SlidingSyncHandler:
                 # https://github.com/matrix-org/matrix-spec-proposals/pull/3575#discussion_r1653045932
                 last_activity_in_room_map[room_id] = room_for_user.event_pos.stream
 
+        for room_id, stream_pos in await self.store.rough_get_last_pos(to_fetch):
+            if stream_pos is not None:
+                last_activity_in_room_map[room_id] = stream_pos
+
         return sorted(
             sync_room_map.values(),
             # Sort by the last activity (stream_ordering) in the room