From 181c1a6072f50d3f4a5d213108d5ff814e70b41e Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 16 Jul 2019 13:31:25 +0100 Subject: [PATCH] Don't decrease left_members if the user is joining for the first time. Fixes #5423 Signed-off-by: Olivier Wilkinson (reivilibre) --- synapse/handlers/stats.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py index 155232e5c3..e7495f8940 100644 --- a/synapse/handlers/stats.py +++ b/synapse/handlers/stats.py @@ -153,21 +153,28 @@ class StatsHandler(StateDeltasHandler): # given we're not testing for a specific result; might as well # just grab the prev_membership and membership strings and # compare them. - prev_event_content = {} + # We take None rather than leave as a previous membership + # in the absence of a previous event because we do not want to + # reduce the leave count when a new-to-the-room user joins. + prev_membership = None if prev_event_id is not None: prev_event = yield self.store.get_event( prev_event_id, allow_none=True ) if prev_event: prev_event_content = prev_event.content + prev_membership = prev_event_content.get( + "membership", Membership.LEAVE + ) membership = event_content.get("membership", Membership.LEAVE) - prev_membership = prev_event_content.get("membership", Membership.LEAVE) if prev_membership == membership: continue - if prev_membership == Membership.JOIN: + if prev_membership is None: + logger.debug("No previous membership for this user.") + elif prev_membership == Membership.JOIN: yield self.store.update_stats_delta( now, "room", room_id, "joined_members", -1 )