From d79caed49336a33cb033ce8b8af22a2e75ef94ee Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 6 Jun 2023 22:12:49 -0500 Subject: [PATCH 1/3] Clean-up query formatting --- synapse/storage/databases/main/roommember.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index ae9c201b87e8..eddf5ed92476 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -131,8 +131,10 @@ def _transact(txn: LoggingTransaction) -> int: query = """ SELECT COUNT(DISTINCT substr(out.user_id, pos+1)) FROM ( - SELECT rm.user_id as user_id, instr(rm.user_id, ':') - AS pos FROM room_memberships as rm + SELECT + rm.user_id AS user_id, + instr(rm.user_id, ':') AS pos + FROM room_memberships as rm INNER JOIN current_state_events as c ON rm.event_id = c.event_id WHERE c.type = 'm.room.member' ) as out From 003267bfcdf97a6b91351bf003d5cea3fd8c3831 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 6 Jun 2023 22:13:49 -0500 Subject: [PATCH 2/3] Remove extra `current_state_events` join --- synapse/storage/databases/main/roommember.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index eddf5ed92476..e6782980bf16 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -132,11 +132,9 @@ def _transact(txn: LoggingTransaction) -> int: SELECT COUNT(DISTINCT substr(out.user_id, pos+1)) FROM ( SELECT - rm.user_id AS user_id, - instr(rm.user_id, ':') AS pos - FROM room_memberships as rm - INNER JOIN current_state_events as c ON rm.event_id = c.event_id - WHERE c.type = 'm.room.member' + user_id AS user_id, + instr(user_id, ':') AS pos + FROM room_memberships ) as out """ else: From 6c3d303880bf9d2d5e3e0f2924de886659527b19 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 6 Jun 2023 22:16:42 -0500 Subject: [PATCH 3/3] Add changelog --- changelog.d/15735.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15735.misc diff --git a/changelog.d/15735.misc b/changelog.d/15735.misc new file mode 100644 index 000000000000..20582bb1ada5 --- /dev/null +++ b/changelog.d/15735.misc @@ -0,0 +1 @@ +Simplify query to `_count_known_servers()` for the `synapse_federation_known_servers` metric.