Make snapshot_all_rooms return results in the correct form, including start and end tokens.

paul/schema_breaking_changes
Erik Johnston 2014-08-18 16:20:21 +01:00
parent 709a92cee8
commit 4eb8f84aa8
2 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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):