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 | |
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.
-rw-r--r-- | synapse/handlers/room.py | 9 | ||||
-rw-r--r-- | synapse/storage/stream.py | 25 |
2 files changed, 28 insertions, 6 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index cdc98d2b08..9e10235fa0 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -269,11 +269,16 @@ class MessageHandler(BaseHandler): if event.membership != Membership.JOIN: continue try: - messages = yield self.store.get_recent_events_for_room( + messages, token = yield self.store.get_recent_events_for_room( event.room_id, limit=50, ) - d["messages"] = [m.get_dict() for m in messages] + + d["messages"] = { + "chunk": [m.get_dict() for m in messages], + "start": token[0], + "end": token[1], + } except: pass 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): |