summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-07-29 17:15:15 +0100
committerGitHub <noreply@github.com>2019-07-29 17:15:15 +0100
commit7c8c3b8437184cbefa2e06c24740549e9a476a8b (patch)
treee7a9de59ae6ad32949ff07e84789ca8435d1c984
parentMerge pull request #5752 from matrix-org/erikj/forgotten_user (diff)
parentNewsfile (diff)
downloadsynapse-7c8c3b8437184cbefa2e06c24740549e9a476a8b.tar.xz
Merge pull request #5774 from matrix-org/erikj/fix_rejected_membership
Fix room summary when rejected events are in state
-rw-r--r--changelog.d/5774.misc1
-rw-r--r--synapse/storage/roommember.py6
2 files changed, 7 insertions, 0 deletions
diff --git a/changelog.d/5774.misc b/changelog.d/5774.misc
new file mode 100644
index 0000000000..5e15dfd5fa
--- /dev/null
+++ b/changelog.d/5774.misc
@@ -0,0 +1 @@
+Reduce database IO usage by optimising queries for current membership.
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index a4936022e7..e60409ed73 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -156,9 +156,12 @@ class RoomMemberWorkerStore(EventsWorkerStore):
             # then we can avoid a join, which is a Very Good Thing given how
             # frequently this function gets called.
             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 = """
                     SELECT count(*), membership FROM current_state_events
                     WHERE type = 'm.room.member' AND room_id = ?
+                        AND membership IS NOT NULL
                     GROUP BY membership
                 """
             else:
@@ -180,10 +183,13 @@ class RoomMemberWorkerStore(EventsWorkerStore):
             # we order by membership and then fairly arbitrarily by event_id so
             # heroes are consistent
             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 = """
                     SELECT state_key, membership, event_id
                     FROM current_state_events
                     WHERE type = 'm.room.member' AND room_id = ?
+                        AND membership IS NOT NULL
                     ORDER BY
                         CASE membership WHEN ? THEN 1 WHEN ? THEN 2 ELSE 3 END ASC,
                         event_id ASC