summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-06-16 17:12:27 +0100
committerErik Johnston <erik@matrix.org>2015-06-16 17:12:27 +0100
commiteceb554a2f3e5bc3d1eb8b4f87c756dfd4c48340 (patch)
tree656ed54ee82af18d6394e2cc27c4a8f99c5db1f6
parentUse DeferredList (diff)
downloadsynapse-eceb554a2f3e5bc3d1eb8b4f87c756dfd4c48340.tar.xz
Use another deferred list
-rw-r--r--synapse/handlers/message.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index de9c6da9ec..e324662f18 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -380,15 +380,6 @@ class MessageHandler(BaseHandler):
         if limit is None:
             limit = 10
 
-        messages, token = yield self.store.get_recent_events_for_room(
-            room_id,
-            limit=limit,
-            end_token=now_token.room_key,
-        )
-
-        start_token = now_token.copy_and_replace("room_key", token[0])
-        end_token = now_token.copy_and_replace("room_key", token[1])
-
         room_members = [
             m for m in current_state.values()
             if m.type == EventTypes.Member
@@ -396,20 +387,38 @@ class MessageHandler(BaseHandler):
         ]
 
         presence_handler = self.hs.get_handlers().presence_handler
-        presence_defs = yield defer.DeferredList(
+
+        @defer.inlineCallbacks
+        def get_presence():
+            presence_defs = yield defer.DeferredList(
+                [
+                    presence_handler.get_state(
+                        target_user=UserID.from_string(m.user_id),
+                        auth_user=auth_user,
+                        as_event=True,
+                        check_auth=False,
+                    )
+                    for m in room_members
+                ],
+                consumeErrors=True,
+            )
+
+            defer.returnValue([p for success, p in presence_defs if success])
+
+        presence, (messages, token) = yield defer.gatherResults(
             [
-                presence_handler.get_state(
-                    target_user=UserID.from_string(m.user_id),
-                    auth_user=auth_user,
-                    as_event=True,
-                    check_auth=False,
+                get_presence(),
+                self.store.get_recent_events_for_room(
+                    room_id,
+                    limit=limit,
+                    end_token=now_token.room_key,
                 )
-                for m in room_members
             ],
             consumeErrors=True,
-        )
+        ).addErrback(unwrapFirstError)
 
-        presence = [p for success, p in presence_defs if success]
+        start_token = now_token.copy_and_replace("room_key", token[0])
+        end_token = now_token.copy_and_replace("room_key", token[1])
 
         time_now = self.clock.time_msec()