summary refs log tree commit diff
path: root/synapse/handlers/presence.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-04-23 19:01:37 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-04-23 19:01:37 +0100
commite1e5e53127540fbaa4e23fbc628113983efd767b (patch)
tree47fe3729e246c192679ec1c6b5335472e22fab35 /synapse/handlers/presence.py
parentDon't let the remote offline serial list grow arbitrarily large (diff)
downloadsynapse-e1e5e53127540fbaa4e23fbc628113983efd767b.tar.xz
Remove users from the remote_offline_serials list (and clean up empty elements) when they go online again
Diffstat (limited to '')
-rw-r--r--synapse/handlers/presence.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index f929bcf853..571eacd343 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -720,14 +720,24 @@ class PresenceHandler(BaseHandler):
                 statuscache=statuscache,
             )
 
+            user_id = user.to_string()
+
             if state["presence"] == PresenceState.OFFLINE:
                 self._remote_offline_serials.insert(
                     0,
-                    (self._user_cachemap_latest_serial, set([user.to_string()]))
+                    (self._user_cachemap_latest_serial, set([user_id]))
                 )
                 while len(self._remote_offline_serials) > MAX_OFFLINE_SERIALS:
                     self._remote_offline_serials.pop()  # remove the oldest
                 del self._user_cachemap[user]
+            else:
+                # Remove the user from remote_offline_serials now that they're
+                # no longer offline
+                for idx, elem in enumerate(self._remote_offline_serials):
+                    (_, user_ids) = elem
+                    user_ids.discard(user_id)
+                    if not user_ids:
+                        self._remote_offline_serials.pop(idx)
 
         for poll in content.get("poll", []):
             user = UserID.from_string(poll)