summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-05-24 14:00:43 +0100
committerErik Johnston <erik@matrix.org>2016-05-24 14:27:19 +0100
commitfaad233ea61cfff2c377609fa1d3c64d39f8a039 (patch)
tree297835b8d793ee53aeac3626b6f518d203b81ea8 /synapse/handlers
parentDon't send down all ephemeral events (diff)
downloadsynapse-faad233ea61cfff2c377609fa1d3c64d39f8a039.tar.xz
Change short circuit path
Diffstat (limited to '')
-rw-r--r--synapse/handlers/sync.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 6f7dd45ef3..3b89582d79 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -273,23 +273,14 @@ class SyncHandler(object):
             a Deferred TimelineBatch
         """
         with Measure(self.clock, "load_filtered_recents"):
-            filtering_factor = 2
             timeline_limit = sync_config.filter_collection.timeline_limit()
-            load_limit = max(timeline_limit * filtering_factor, 10)
-            max_repeat = 5  # Only try a few times per room, otherwise
-            room_key = now_token.room_key
-            end_key = room_key
 
             if recents is None or newly_joined_room or timeline_limit < len(recents):
                 limited = True
             else:
                 limited = False
 
-            if since_token:
-                if not now_token.is_after(since_token):
-                    limited = False
-
-            if recents is not None:
+            if recents:
                 recents = sync_config.filter_collection.filter_room_timeline(recents)
                 recents = yield filter_events_for_client(
                     self.store,
@@ -299,6 +290,19 @@ class SyncHandler(object):
             else:
                 recents = []
 
+            if not limited:
+                defer.returnValue(TimelineBatch(
+                    events=recents,
+                    prev_batch=now_token,
+                    limited=False
+                ))
+
+            filtering_factor = 2
+            load_limit = max(timeline_limit * filtering_factor, 10)
+            max_repeat = 5  # Only try a few times per room, otherwise
+            room_key = now_token.room_key
+            end_key = room_key
+
             since_key = None
             if since_token and not newly_joined_room:
                 since_key = since_token.room_key
@@ -939,18 +943,24 @@ class SyncHandler(object):
             always_include(bool): Always include this room in the sync response,
                 even if empty.
         """
-        since_token = sync_result_builder.since_token
-        now_token = sync_result_builder.now_token
-        sync_config = sync_result_builder.sync_config
-
-        room_id = room_builder.room_id
-        events = room_builder.events
         newly_joined = room_builder.newly_joined
         full_state = (
             room_builder.full_state
             or newly_joined
             or sync_result_builder.full_state
         )
+        events = room_builder.events
+
+        # We want to shortcut out as early as possible.
+        if not (always_include or account_data or ephemeral or full_state):
+            if events == [] and tags is None:
+                return
+
+        since_token = sync_result_builder.since_token
+        now_token = sync_result_builder.now_token
+        sync_config = sync_result_builder.sync_config
+
+        room_id = room_builder.room_id
         since_token = room_builder.since_token
         upto_token = room_builder.upto_token