diff options
author | Erik Johnston <erik@matrix.org> | 2015-05-21 14:54:40 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-05-21 14:54:40 +0100 |
commit | a551c5dad7e3643f36654a374f6a0d5700b7ea7f (patch) | |
tree | 890d81728370049070b959af72390fee80504f7c /synapse/storage/stream.py | |
parent | Handle the case when things return empty but non none things (diff) | |
parent | s/for events/for requests for events/ (diff) | |
download | synapse-a551c5dad7e3643f36654a374f6a0d5700b7ea7f.tar.xz |
Merge pull request #155 from matrix-org/erikj/perf
Bulk and batch retrieval of events.
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r-- | synapse/storage/stream.py | 43 |
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) |