summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-23 17:25:44 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-23 17:25:50 +0000
commited008e85a8a2d9254d4d6f23cc7eb47ee52d0989 (patch)
tree840937b08bf531c12ed8f47a25bfaf733f832712 /synapse/handlers
parentPut a cache on get_aliases_for_room (diff)
downloadsynapse-ed008e85a8a2d9254d4d6f23cc7eb47ee52d0989.tar.xz
Reduce activity timer granularity to avoid too many quick updates (SYN-247)
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/presence.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 731df00648..bbc7a0f200 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -33,6 +33,10 @@ logger = logging.getLogger(__name__)
 metrics = synapse.metrics.get_metrics_for(__name__)
 
 
+# Don't bother bumping "last active" time if it differs by less than 60 seconds
+LAST_ACTIVE_GRANULARITY = 60*1000
+
+
 # TODO(paul): Maybe there's one of these I can steal from somewhere
 def partition(l, func):
     """Partition the list by the result of func applied to each element."""
@@ -282,6 +286,10 @@ class PresenceHandler(BaseHandler):
         if now is None:
             now = self.clock.time_msec()
 
+        prev_state = self._get_or_make_usercache(user)
+        if now - prev_state.state.get("last_active", 0) < LAST_ACTIVE_GRANULARITY:
+            return
+
         self.changed_presencelike_data(user, {"last_active": now})
 
     def changed_presencelike_data(self, user, state):