summary refs log tree commit diff
path: root/synapse/handlers/sliding_sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2024-07-10 15:30:22 +0100
committerErik Johnston <erik@matrix.org>2024-07-10 15:30:22 +0100
commitbdd1e9eddb7d455705cb7ee93df9bc1fb93f5c15 (patch)
treea99f3e1d7d194d51e21f9df10c2541ab1276d56d /synapse/handlers/sliding_sync.py
parentFixup (diff)
downloadsynapse-bdd1e9eddb7d455705cb7ee93df9bc1fb93f5c15.tar.xz
Fixup
Diffstat (limited to 'synapse/handlers/sliding_sync.py')
-rw-r--r--synapse/handlers/sliding_sync.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py
index cbaad11a61..0fb7e05b5d 100644
--- a/synapse/handlers/sliding_sync.py
+++ b/synapse/handlers/sliding_sync.py
@@ -1012,11 +1012,31 @@ class SlidingSyncHandler:
             A sorted list of room IDs by `stream_ordering` along with membership information.
         """
 
+        self.store._events_stream_cache._entity_to_key
+
         # XXX: FIXUP
         last_activity_in_room_map = await self.store.rough_get_last_pos(
-            sync_room_map.keys()
+            [
+                room_id
+                for room_id, room_for_user in sync_room_map.items()
+                if room_for_user.membership == Membership.JOIN
+            ]
         )
 
+        last_activity_in_room_map = {}
+        to_fetch = []
+        for room_id, room_for_user in sync_room_map.items():
+            if room_for_user.membership == Membership.JOIN:
+                stream_pos = self.store._events_stream_cache._entity_to_key.get(room_id)
+                if stream_pos is not None:
+                    last_activity_in_room_map[room_id] = stream_pos
+                else:
+                    to_fetch.ap(room_id)
+            else:
+                last_activity_in_room_map[room_id] = room_for_user.event_pos.stream
+
+        last_activity_in_room_map.update(await self.store.rough_get_last_pos(to_fetch))
+
         return sorted(
             sync_room_map.values(),
             # Sort by the last activity (stream_ordering) in the room