Fix up get_current_state and get_room_name_and_aliases queries to parse events in transaction
This commit is contained in:
parent
69d4063651
commit
f383d5a801
|
@ -188,26 +188,21 @@ class RoomStore(SQLBaseStore):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_room_name_and_aliases(self, room_id):
|
def get_room_name_and_aliases(self, room_id):
|
||||||
del_sql = (
|
def f(txn):
|
||||||
"SELECT event_id FROM redactions WHERE redacts = e.event_id "
|
sql = (
|
||||||
"LIMIT 1"
|
"SELECT event_id FROM events current_state_events "
|
||||||
|
"WHERE room_id = ? "
|
||||||
)
|
)
|
||||||
|
|
||||||
sql = (
|
sql += " AND ((type = 'm.room.name' AND state_key = '')"
|
||||||
"SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
|
sql += " OR type = 'm.room.aliases')"
|
||||||
"INNER JOIN current_state_events as c ON e.event_id = c.event_id "
|
|
||||||
"WHERE c.room_id = ? "
|
|
||||||
) % {
|
|
||||||
"redacted": del_sql,
|
|
||||||
}
|
|
||||||
|
|
||||||
sql += " AND ((c.type = 'm.room.name' AND c.state_key = '')"
|
txn.execute(sql, (room_id,))
|
||||||
sql += " OR c.type = 'm.room.aliases')"
|
results = self.cursor_to_dict(txn)
|
||||||
args = (room_id,)
|
|
||||||
|
|
||||||
results = yield self._execute_and_decode("get_current_state", sql, *args)
|
return self._parse_events_txn(txn, results)
|
||||||
|
|
||||||
events = yield self._parse_events(results)
|
events = yield self.runInteraction("get_room_name_and_aliases", f)
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
aliases = []
|
aliases = []
|
||||||
|
|
|
@ -128,9 +128,9 @@ 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=""):
|
||||||
|
def f(txn):
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT e.*, r.event_id FROM events as e"
|
"SELECT e.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"
|
" INNER JOIN current_state_events as c ON e.event_id = c.event_id"
|
||||||
" WHERE c.room_id = ? "
|
" WHERE c.room_id = ? "
|
||||||
)
|
)
|
||||||
|
@ -144,9 +144,12 @@ class StateStore(SQLBaseStore):
|
||||||
else:
|
else:
|
||||||
args = (room_id, )
|
args = (room_id, )
|
||||||
|
|
||||||
results = yield self._execute_and_decode("get_current_state", sql, *args)
|
txn.execute(sql, args)
|
||||||
|
results = self.cursor_to_dict(txn)
|
||||||
|
|
||||||
events = yield self._parse_events(results)
|
return self._parse_events_txn(results)
|
||||||
|
|
||||||
|
events = self.runInteraction("get_current_state", f)
|
||||||
defer.returnValue(events)
|
defer.returnValue(events)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue