0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-11 20:42:23 +01:00

Merge pull request #5774 from matrix-org/erikj/fix_rejected_membership

Fix room summary when rejected events are in state
This commit is contained in:
Erik Johnston 2019-07-29 17:15:15 +01:00 committed by GitHub
commit 7c8c3b8437
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

1
changelog.d/5774.misc Normal file
View file

@ -0,0 +1 @@
Reduce database IO usage by optimising queries for current membership.

View file

@ -156,9 +156,12 @@ class RoomMemberWorkerStore(EventsWorkerStore):
# then we can avoid a join, which is a Very Good Thing given how # then we can avoid a join, which is a Very Good Thing given how
# frequently this function gets called. # frequently this function gets called.
if self._current_state_events_membership_up_to_date: if self._current_state_events_membership_up_to_date:
# Note, rejected events will have a null membership field, so
# we we manually filter them out.
sql = """ sql = """
SELECT count(*), membership FROM current_state_events SELECT count(*), membership FROM current_state_events
WHERE type = 'm.room.member' AND room_id = ? WHERE type = 'm.room.member' AND room_id = ?
AND membership IS NOT NULL
GROUP BY membership GROUP BY membership
""" """
else: else:
@ -180,10 +183,13 @@ 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
if self._current_state_events_membership_up_to_date: if self._current_state_events_membership_up_to_date:
# Note, rejected events will have a null membership field, so
# we we manually filter them out.
sql = """ sql = """
SELECT state_key, membership, event_id SELECT state_key, membership, event_id
FROM current_state_events FROM current_state_events
WHERE type = 'm.room.member' AND room_id = ? WHERE type = 'm.room.member' AND room_id = ?
AND membership IS NOT NULL
ORDER BY ORDER BY
CASE membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC, CASE membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC,
event_id ASC event_id ASC