summary refs log tree commit diff
path: root/synapse/handlers/room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-02-01 17:23:44 +0000
committerErik Johnston <erik@matrix.org>2016-02-01 17:23:44 +0000
commit7a8ea7e78bb1a630b215793fd1aac18f06ce7373 (patch)
treee1370adf48d36f3e0f9d5c02ce305d56f3dc75b3 /synapse/handlers/room.py
parentMerge pull request #543 from matrix-org/erikj/sync (diff)
parentOrder things correctly (diff)
downloadsynapse-7a8ea7e78bb1a630b215793fd1aac18f06ce7373.tar.xz
Merge pull request #546 from matrix-org/erikj/events
Switch over /events to use per room caches
Diffstat (limited to 'synapse/handlers/room.py')
-rw-r--r--synapse/handlers/room.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 58e2d25f97..a71cba8ef1 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -1008,15 +1008,30 @@ class RoomEventSource(object):
                 limit=limit,
             )
         else:
-            events, end_key = yield self.store.get_room_events_stream(
-                user_id=user.to_string(),
+            room_events = yield self.store.get_room_changes_for_user(
+                user.to_string(), from_key, to_key
+            )
+
+            room_to_events = yield self.store.get_room_events_stream_for_rooms(
+                room_ids=room_ids,
                 from_key=from_key,
                 to_key=to_key,
-                limit=limit,
-                room_ids=room_ids,
-                is_guest=is_guest,
+                limit=limit or 10,
             )
 
+            events = list(room_events)
+            events.extend(e for evs, _ in room_to_events.values() for e in evs)
+
+            events.sort(key=lambda e: e.internal_metadata.order)
+
+            if limit:
+                events[:] = events[:limit]
+
+            if events:
+                end_key = events[-1].internal_metadata.after
+            else:
+                end_key = to_key
+
         defer.returnValue((events, end_key))
 
     def get_current_key(self, direction='f'):