From 6f8c3df28ae1c1900125614cdcfca1fdccb5153a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 12 Nov 2020 19:01:18 +0000 Subject: [PATCH] Add knock membership events to stats generation --- synapse/handlers/stats.py | 5 +++++ .../delta/58/24add_knock_members_to_stats.sql | 17 +++++++++++++++++ synapse/storage/databases/main/stats.py | 1 + 3 files changed, 23 insertions(+) create mode 100644 synapse/storage/databases/main/schema/delta/58/24add_knock_members_to_stats.sql diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py index dc62b21c06f9..3961f727aa50 100644 --- a/synapse/handlers/stats.py +++ b/synapse/handlers/stats.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2018 New Vector Ltd +# Copyright 2020 Sorunome # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -225,6 +226,8 @@ async def _handle_deltas(self, deltas): room_stats_delta["left_members"] -= 1 elif prev_membership == Membership.BAN: room_stats_delta["banned_members"] -= 1 + elif prev_membership == Membership.KNOCK: + room_stats_delta["knocked_members"] -= 1 else: raise ValueError( "%r is not a valid prev_membership" % (prev_membership,) @@ -246,6 +249,8 @@ async def _handle_deltas(self, deltas): room_stats_delta["left_members"] += 1 elif membership == Membership.BAN: room_stats_delta["banned_members"] += 1 + elif membership == Membership.KNOCK: + room_stats_delta["knocked_members"] += 1 else: raise ValueError("%r is not a valid membership" % (membership,)) diff --git a/synapse/storage/databases/main/schema/delta/58/24add_knock_members_to_stats.sql b/synapse/storage/databases/main/schema/delta/58/24add_knock_members_to_stats.sql new file mode 100644 index 000000000000..0c098fbcbc90 --- /dev/null +++ b/synapse/storage/databases/main/schema/delta/58/24add_knock_members_to_stats.sql @@ -0,0 +1,17 @@ +/* Copyright 2020 Sorunome + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +ALTER TABLE room_stats_current ADD knock_members INT NOT NULL DEFAULT '0'; +ALTER TABLE room_stats_historical ADD knock_members BIGINT NOT NULL DEFAULT '0'; diff --git a/synapse/storage/databases/main/stats.py b/synapse/storage/databases/main/stats.py index 0cdb3ec1f7ff..62b75515170d 100644 --- a/synapse/storage/databases/main/stats.py +++ b/synapse/storage/databases/main/stats.py @@ -41,6 +41,7 @@ "current_state_events", "joined_members", "invited_members", + "knocked_members", "left_members", "banned_members", "local_users_in_room",