Remove join when calculating room summaries.

This commit is contained in:
Erik Johnston 2019-07-24 11:49:15 +01:00
parent 62921fb53e
commit 0c4a99607e

View file

@ -179,19 +179,27 @@ class RoomMemberWorkerStore(EventsWorkerStore):
# we order by membership and then fairly arbitrarily by event_id so # we order by membership and then fairly arbitrarily by event_id so
# heroes are consistent # heroes are consistent
sql = """ if self._current_state_events_membership_up_to_date:
SELECT m.user_id, m.membership, m.event_id sql = """
FROM room_memberships as m SELECT state_key, membership, event_id
INNER JOIN current_state_events as c FROM current_state_events
ON m.event_id = c.event_id WHERE type = 'm.room.member' AND room_id = ?
AND m.room_id = c.room_id ORDER BY
AND m.user_id = c.state_key CASE membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC,
WHERE c.type = 'm.room.member' AND c.room_id = ? event_id ASC
ORDER BY LIMIT ?
CASE m.membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC, """
m.event_id ASC else:
LIMIT ? sql = """
""" SELECT c.state_key, m.membership, c.event_id
FROM room_memberships as m
INNER JOIN current_state_events as c USING (room_id, event_id)
WHERE c.type = 'm.room.member' AND c.room_id = ?
ORDER BY
CASE m.membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC,
c.event_id ASC
LIMIT ?
"""
# 6 is 5 (number of heroes) plus 1, in case one of them is the calling user. # 6 is 5 (number of heroes) plus 1, in case one of them is the calling user.
txn.execute(sql, (room_id, Membership.JOIN, Membership.INVITE, 6)) txn.execute(sql, (room_id, Membership.JOIN, Membership.INVITE, 6))