From 03c0da9f65ce2fb9752aacd6a85419a000d86ff0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 22 Jan 2015 13:58:25 +0000 Subject: [PATCH] In get_recent_events_for_room, get the full event json rather than just the event_ids so we don't have to do so many db queries --- synapse/storage/stream.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index 8ac2adab05..12eacb91c0 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -269,8 +269,11 @@ class StreamStore(SQLBaseStore): # TODO (erikj): Handle compressed feedback sql = ( - "SELECT stream_ordering, topological_ordering, event_id FROM events " - "WHERE room_id = ? AND stream_ordering <= ? AND outlier = 0 " + "SELECT stream_ordering, topological_ordering, " + "internal_metadata, json, r.event_id FROM events as e " + "LEFT JOIN event_json as ej ON e.event_id = ej.event_id " + "LEFT JOIN redactions as r ON e.event_id = r.redacts " + "WHERE e.room_id = ? AND stream_ordering <= ? AND outlier = 0 " "ORDER BY topological_ordering DESC, stream_ordering DESC LIMIT ? " ) @@ -295,11 +298,15 @@ class StreamStore(SQLBaseStore): else: token = (end_token, end_token) - events = self._get_events_txn( - txn, - [r["event_id"] for r in rows], - get_prev_content=True - ) + events = [ + self._get_event_from_row_txn( + txn, + r["internal_metadata"], + r["json"], + r["event_id"], + ) + for r in rows + ] return events, token