summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/handlers/stats.py42
1 files changed, 14 insertions, 28 deletions
diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py
index 3dbc0a2434..b3d59fde05 100644
--- a/synapse/handlers/stats.py
+++ b/synapse/handlers/stats.py
@@ -161,9 +161,7 @@ class StatsHandler(StateDeltasHandler):
             if prev_event_id is None:
                 # this state event doesn't overwrite another,
                 # so it is a new effective/current state event
-                room_stats_delta["current_state_events"] = (
-                    room_stats_delta.get("current_state_events", 0) + 1
-                )
+                room_stats_delta["current_state_events"] = 1
 
             if typ == EventTypes.Member:
                 # we could use _get_key_change here but it's a bit inefficient
@@ -188,43 +186,31 @@ class StatsHandler(StateDeltasHandler):
 
                 if prev_membership is None:
                     logger.debug("No previous membership for this user.")
+                elif membership == prev_membership:
+                    pass  # noop
                 elif prev_membership == Membership.JOIN:
-                    room_stats_delta["joined_members"] = (
-                        room_stats_delta.get("joined_members", 0) - 1
-                    )
+                    room_stats_delta["joined_members"] = -1
                 elif prev_membership == Membership.INVITE:
-                    room_stats_delta["invited_members"] = (
-                        room_stats_delta.get("invited_members", 0) - 1
-                    )
+                    room_stats_delta["invited_members"] = -1
                 elif prev_membership == Membership.LEAVE:
-                    room_stats_delta["left_members"] = (
-                        room_stats_delta.get("left_members", 0) - 1
-                    )
+                    room_stats_delta["left_members"] = -1
                 elif prev_membership == Membership.BAN:
-                    room_stats_delta["banned_members"] = (
-                        room_stats_delta.get("banned_members", 0) - 1
-                    )
+                    room_stats_delta["banned_members"] = -1
                 else:
                     err = "%s is not a valid prev_membership" % (repr(prev_membership),)
                     logger.error(err)
                     raise ValueError(err)
 
+                if membership == prev_membership:
+                    pass  # noop
                 if membership == Membership.JOIN:
-                    room_stats_delta["joined_members"] = (
-                        room_stats_delta.get("joined_members", 0) + 1
-                    )
+                    room_stats_delta["joined_members"] = +1
                 elif membership == Membership.INVITE:
-                    room_stats_delta["invited_members"] = (
-                        room_stats_delta.get("invited_members", 0) + 1
-                    )
+                    room_stats_delta["invited_members"] = +1
                 elif membership == Membership.LEAVE:
-                    room_stats_delta["left_members"] = (
-                        room_stats_delta.get("left_members", 0) + 1
-                    )
+                    room_stats_delta["left_members"] = +1
                 elif membership == Membership.BAN:
-                    room_stats_delta["banned_members"] = (
-                        room_stats_delta.get("banned_members", 0) + 1
-                    )
+                    room_stats_delta["banned_members"] = +1
                 else:
                     err = "%s is not a valid membership" % (repr(membership),)
                     logger.error(err)
@@ -234,7 +220,7 @@ class StatsHandler(StateDeltasHandler):
                 if self.is_mine_id(user_id) and membership in (
                     Membership.JOIN,
                     Membership.LEAVE,
-                ):
+                ) and prev_membership != membership:
                     # update user_stats as it's one of our users
                     public = yield self._is_public_room(room_id)