diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-18 16:20:21 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-18 16:20:21 +0100 |
commit | 4eb8f84aa8fc735e228f66d11c355625bb14c1cf (patch) | |
tree | f61a3382178abf2193c05949d034a9b3ff52c9d1 /synapse/storage | |
parent | SQL doesn't allow AUTOINCREMENT on non PRIMARY KEY columns. (diff) | |
download | synapse-4eb8f84aa8fc735e228f66d11c355625bb14c1cf.tar.xz |
Make snapshot_all_rooms return results in the correct form, including start and end tokens.
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/stream.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index f7968f576f..6728a4b5ea 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -104,19 +104,36 @@ class StreamStore(SQLBaseStore): def get_recent_events_for_room(self, room_id, limit, with_feedback=False): # TODO (erikj): Handle compressed feedback + end_token = yield self.get_room_events_max_id() + sql = ( - "SELECT * FROM events WHERE room_id = ? " - "ORDER BY token_ordering, rowid DESC LIMIT ? " + "SELECT * FROM events WHERE " + "WHERE room_id = ? AND token_ordering <= ? " + "ORDER BY topological_ordering, rowid DESC LIMIT ? " ) rows = yield self._execute_and_decode( sql, - room_id, limit + room_id, end_token, limit ) rows.reverse() # As we selected with reverse ordering - defer.returnValue([self._parse_event_from_row(r) for r in rows]) + if rows: + topo = rows[0]["topological_ordering"] + row_id = rows[0]["rowid"] + start_token = "p%s-%s" % (topo, row_id) + + token = (start_token, end_token) + else: + token = ("START", end_token) + + defer.returnValue( + ( + [self._parse_event_from_row(r) for r in rows], + token + ) + ) @defer.inlineCallbacks def get_room_events_max_id(self): |