summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-21 14:58:47 +0100
committerErik Johnston <erik@matrix.org>2015-05-21 14:58:47 +0100
commitc2633907c530d018254c0cca8d7ce8336c380fc2 (patch)
treec55895df895f013398702154ed85940e19ab2d0e /synapse/storage/stream.py
parentFix _get_backfill_events to return events in the correct order (diff)
parentMerge branch 'develop' of github.com:matrix-org/synapse into erikj/join_perf (diff)
downloadsynapse-c2633907c530d018254c0cca8d7ce8336c380fc2.tar.xz
Merge branch 'erikj/join_perf' of github.com:matrix-org/synapse into erikj/backfill_fixes
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 8045e17fd7..af45fc5619 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -224,7 +224,7 @@ class StreamStore(SQLBaseStore):
 
         return self.runInteraction("get_room_events_stream", f)
 
-    @log_function
+    @defer.inlineCallbacks
     def paginate_room_events(self, room_id, from_key, to_key=None,
                              direction='b', limit=-1,
                              with_feedback=False):
@@ -286,18 +286,20 @@ class StreamStore(SQLBaseStore):
                 # TODO (erikj): We should work out what to do here instead.
                 next_token = to_key if to_key else from_key
 
-            events = self._get_events_txn(
-                txn,
-                [r["event_id"] for r in rows],
-                get_prev_content=True
-            )
+            return rows, next_token,
+
+        rows, token = yield self.runInteraction("paginate_room_events", f)
 
-            self._set_before_and_after(events, rows)
+        events = yield self._get_events(
+            [r["event_id"] for r in rows],
+            get_prev_content=True
+        )
 
-            return events, next_token,
+        self._set_before_and_after(events, rows)
 
-        return self.runInteraction("paginate_room_events", f)
+        defer.returnValue((events, token))
 
+    @defer.inlineCallbacks
     def get_recent_events_for_room(self, room_id, limit, end_token,
                                    with_feedback=False, from_token=None):
         # TODO (erikj): Handle compressed feedback
@@ -349,20 +351,23 @@ class StreamStore(SQLBaseStore):
             else:
                 token = (str(end_token), str(end_token))
 
-            events = self._get_events_txn(
-                txn,
-                [r["event_id"] for r in rows],
-                get_prev_content=True
-            )
-
-            self._set_before_and_after(events, rows)
-
-            return events, token
+            return rows, token
 
-        return self.runInteraction(
+        rows, token = yield self.runInteraction(
             "get_recent_events_for_room", get_recent_events_for_room_txn
         )
 
+        logger.debug("stream before")
+        events = yield self._get_events(
+            [r["event_id"] for r in rows],
+            get_prev_content=True
+        )
+        logger.debug("stream after")
+
+        self._set_before_and_after(events, rows)
+
+        defer.returnValue((events, token))
+
     @defer.inlineCallbacks
     def get_room_events_max_id(self, direction='f'):
         token = yield self._stream_id_gen.get_max_token(self)