diff options
author | Erik Johnston <erik@matrix.org> | 2015-04-30 17:12:52 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-04-30 17:12:52 +0100 |
commit | f383d5a8011a8cbef7aa92d247e1f725a60fa82a (patch) | |
tree | 5dc177d5f8935326a6f9d0f030058bed1c00d1fc /synapse/storage/state.py | |
parent | Add get_rooms_for_user cache (diff) | |
download | synapse-f383d5a8011a8cbef7aa92d247e1f725a60fa82a.tar.xz |
Fix up get_current_state and get_room_name_and_aliases queries to parse events in transaction
Diffstat (limited to '')
-rw-r--r-- | synapse/storage/state.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py index 95bc15c0dc..8b3ed244af 100644 --- a/synapse/storage/state.py +++ b/synapse/storage/state.py @@ -128,25 +128,28 @@ class StateStore(SQLBaseStore): @defer.inlineCallbacks def get_current_state(self, room_id, event_type=None, state_key=""): - sql = ( - "SELECT e.*, r.event_id FROM events as e" - " LEFT JOIN redactions as r ON r.redacts = e.event_id" - " INNER JOIN current_state_events as c ON e.event_id = c.event_id" - " WHERE c.room_id = ? " - ) + def f(txn): + sql = ( + "SELECT e.event_id FROM events as e" + " INNER JOIN current_state_events as c ON e.event_id = c.event_id" + " WHERE c.room_id = ? " + ) + + if event_type and state_key is not None: + sql += " AND c.type = ? AND c.state_key = ? " + args = (room_id, event_type, state_key) + elif event_type: + sql += " AND c.type = ?" + args = (room_id, event_type) + else: + args = (room_id, ) - if event_type and state_key is not None: - sql += " AND c.type = ? AND c.state_key = ? " - args = (room_id, event_type, state_key) - elif event_type: - sql += " AND c.type = ?" - args = (room_id, event_type) - else: - args = (room_id, ) + txn.execute(sql, args) + results = self.cursor_to_dict(txn) - results = yield self._execute_and_decode("get_current_state", sql, *args) + return self._parse_events_txn(results) - events = yield self._parse_events(results) + events = self.runInteraction("get_current_state", f) defer.returnValue(events) |