summary refs log tree commit diff
path: root/synapse/handlers/sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-05-09 11:59:45 +0100
committerErik Johnston <erik@matrix.org>2018-05-09 13:43:39 +0100
commite2accd7f1d21e34181dd4543eca30ad1ea971b4c (patch)
treeabfd1d074f7a123141bceeba345b47467822a8b2 /synapse/handlers/sync.py
parentDon't unnecessarily require token to be stream token (diff)
downloadsynapse-e2accd7f1d21e34181dd4543eca30ad1ea971b4c.tar.xz
Refactor sync APIs to reuse pagination API
The sync API often returns events in a topological rather than stream
ordering, e.g. when the user joined the room or on initial sync. When
this happens we can reuse existing pagination storage functions.
Diffstat (limited to 'synapse/handlers/sync.py')
-rw-r--r--synapse/handlers/sync.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index c25a76d215..b75daa340d 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -354,12 +354,19 @@ class SyncHandler(object):
                 since_key = since_token.room_key
 
             while limited and len(recents) < timeline_limit and max_repeat:
-                events, end_key = yield self.store.get_room_events_stream_for_room(
-                    room_id,
-                    limit=load_limit + 1,
-                    from_key=since_key,
-                    to_key=end_key,
-                )
+                if since_key:
+                    events, end_key = yield self.store.get_room_events_stream_for_room(
+                        room_id,
+                        limit=load_limit + 1,
+                        from_key=since_key,
+                        to_key=end_key,
+                    )
+                else:
+                    events, end_key = yield self.store.get_recent_events_for_room(
+                        room_id,
+                        limit=load_limit + 1,
+                        end_token=end_key,
+                    )
                 loaded_recents = sync_config.filter_collection.filter_room_timeline(
                     events
                 )