Don't use sub queries, it makes postgres sad

This commit is contained in:
Erik Johnston 2015-04-30 16:16:53 +01:00
parent 29400b45b9
commit 3c4c229788

View File

@ -128,18 +128,12 @@ class StateStore(SQLBaseStore):
@defer.inlineCallbacks @defer.inlineCallbacks
def get_current_state(self, room_id, event_type=None, state_key=""): def get_current_state(self, room_id, event_type=None, state_key=""):
del_sql = (
"SELECT event_id FROM redactions WHERE redacts = e.event_id "
"LIMIT 1"
)
sql = ( sql = (
"SELECT e.*, (%(redacted)s) AS redacted FROM events as e " "SELECT e.*, r.event_id FROM events as e"
"INNER JOIN current_state_events as c ON e.event_id = c.event_id " " LEFT JOIN redactions as r ON r.redacts = e.event_id"
"WHERE c.room_id = ? " " INNER JOIN current_state_events as c ON e.event_id = c.event_id"
) % { " WHERE c.room_id = ? "
"redacted": del_sql, )
}
if event_type and state_key is not None: if event_type and state_key is not None:
sql += " AND c.type = ? AND c.state_key = ? " sql += " AND c.type = ? AND c.state_key = ? "