mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-26 11:36:03 +03:00
Replace some calls to cursor_to_dict
cursor_to_dict can be surprisinglh expensive for large result sets, so lets only call it when we need to.
This commit is contained in:
parent
e71940aa64
commit
d58b1ffe94
3 changed files with 13 additions and 39 deletions
|
@ -167,7 +167,6 @@ class SlavedEventStore(BaseSlavedStore):
|
||||||
_get_rooms_for_user_where_membership_is_txn = (
|
_get_rooms_for_user_where_membership_is_txn = (
|
||||||
DataStore._get_rooms_for_user_where_membership_is_txn.__func__
|
DataStore._get_rooms_for_user_where_membership_is_txn.__func__
|
||||||
)
|
)
|
||||||
_get_members_rows_txn = DataStore._get_members_rows_txn.__func__
|
|
||||||
_get_state_for_groups = DataStore._get_state_for_groups.__func__
|
_get_state_for_groups = DataStore._get_state_for_groups.__func__
|
||||||
_get_all_state_from_cache = DataStore._get_all_state_from_cache.__func__
|
_get_all_state_from_cache = DataStore._get_all_state_from_cache.__func__
|
||||||
_get_events_around_txn = DataStore._get_events_around_txn.__func__
|
_get_events_around_txn = DataStore._get_events_around_txn.__func__
|
||||||
|
|
|
@ -132,14 +132,17 @@ class RoomMemberStore(SQLBaseStore):
|
||||||
@cached(max_entries=500000, iterable=True)
|
@cached(max_entries=500000, iterable=True)
|
||||||
def get_users_in_room(self, room_id):
|
def get_users_in_room(self, room_id):
|
||||||
def f(txn):
|
def f(txn):
|
||||||
|
sql = (
|
||||||
rows = self._get_members_rows_txn(
|
"SELECT m.user_id FROM room_memberships as m"
|
||||||
txn,
|
" INNER JOIN current_state_events as c"
|
||||||
room_id=room_id,
|
" ON m.event_id = c.event_id "
|
||||||
membership=Membership.JOIN,
|
" AND m.room_id = c.room_id "
|
||||||
|
" AND m.user_id = c.state_key"
|
||||||
|
" WHERE c.type = 'm.room.member' AND c.room_id = ? AND m.membership = ?"
|
||||||
)
|
)
|
||||||
|
|
||||||
return [r["user_id"] for r in rows]
|
txn.execute(sql, (room_id, Membership.JOIN,))
|
||||||
|
return [r[0] for r in txn]
|
||||||
return self.runInteraction("get_users_in_room", f)
|
return self.runInteraction("get_users_in_room", f)
|
||||||
|
|
||||||
@cached()
|
@cached()
|
||||||
|
@ -246,34 +249,6 @@ class RoomMemberStore(SQLBaseStore):
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _get_members_rows_txn(self, txn, room_id, membership=None, user_id=None):
|
|
||||||
where_clause = "c.room_id = ?"
|
|
||||||
where_values = [room_id]
|
|
||||||
|
|
||||||
if membership:
|
|
||||||
where_clause += " AND m.membership = ?"
|
|
||||||
where_values.append(membership)
|
|
||||||
|
|
||||||
if user_id:
|
|
||||||
where_clause += " AND m.user_id = ?"
|
|
||||||
where_values.append(user_id)
|
|
||||||
|
|
||||||
sql = (
|
|
||||||
"SELECT m.* FROM room_memberships as m"
|
|
||||||
" INNER JOIN current_state_events as c"
|
|
||||||
" ON m.event_id = c.event_id "
|
|
||||||
" AND m.room_id = c.room_id "
|
|
||||||
" AND m.user_id = c.state_key"
|
|
||||||
" WHERE c.type = 'm.room.member' AND %(where)s"
|
|
||||||
) % {
|
|
||||||
"where": where_clause,
|
|
||||||
}
|
|
||||||
|
|
||||||
txn.execute(sql, where_values)
|
|
||||||
rows = self.cursor_to_dict(txn)
|
|
||||||
|
|
||||||
return rows
|
|
||||||
|
|
||||||
@cachedInlineCallbacks(max_entries=500000, iterable=True)
|
@cachedInlineCallbacks(max_entries=500000, iterable=True)
|
||||||
def get_rooms_for_user(self, user_id):
|
def get_rooms_for_user(self, user_id):
|
||||||
"""Returns a set of room_ids the user is currently joined to
|
"""Returns a set of room_ids the user is currently joined to
|
||||||
|
|
|
@ -342,10 +342,10 @@ class StateStore(SQLBaseStore):
|
||||||
args.extend(where_args)
|
args.extend(where_args)
|
||||||
|
|
||||||
txn.execute(sql % (where_clause,), args)
|
txn.execute(sql % (where_clause,), args)
|
||||||
rows = self.cursor_to_dict(txn)
|
for row in txn:
|
||||||
for row in rows:
|
typ, state_key, event_id = row
|
||||||
key = (row["type"], row["state_key"])
|
key = (typ, state_key)
|
||||||
results[group][key] = row["event_id"]
|
results[group][key] = event_id
|
||||||
else:
|
else:
|
||||||
if types is not None:
|
if types is not None:
|
||||||
where_clause = "AND (%s)" % (
|
where_clause = "AND (%s)" % (
|
||||||
|
|
Loading…
Reference in a new issue