summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-12-01 11:06:40 +0000
committerErik Johnston <erik@matrix.org>2015-12-01 11:06:40 +0000
commitda7dd586414653a3d7d3ae4225600cb5126059f5 (patch)
treeb7eced57920d90f1229384d73dde54320dd6879b /synapse
parentAllow paginating search ordered by recents (diff)
downloadsynapse-da7dd586414653a3d7d3ae4225600cb5126059f5.tar.xz
Tidy up a bit
Diffstat (limited to '')
-rw-r--r--synapse/handlers/search.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py
index 671dbb61b8..df6390cf05 100644
--- a/synapse/handlers/search.py
+++ b/synapse/handlers/search.py
@@ -226,19 +226,20 @@ class SearchHandler(BaseHandler):
 
                 if len(results) < search_filter.limit() * 2:
                     pagination_token = None
+                    break
                 else:
                     pagination_token = results[-1]["pagination_token"]
 
-            if room_events:
-                for event in room_events:
-                    group = room_groups.setdefault(event.room_id, {
-                        "results": [],
-                    })
-                    group["results"].append(event.event_id)
+            for event in room_events:
+                group = room_groups.setdefault(event.room_id, {
+                    "results": [],
+                })
+                group["results"].append(event.event_id)
 
-            pagination_token = results_map[room_events[-1].event_id]["pagination_token"]
+            if room_events and len(room_events) >= search_filter.limit():
+                last_event_id = room_events[-1].event_id
+                pagination_token = results_map[last_event_id]["pagination_token"]
 
-            if pagination_token:
                 global_next_batch = encode_base64("%s\n%s\n%s" % (
                     "all", "", pagination_token
                 ))