summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-08 13:58:32 +0100
committerErik Johnston <erik@matrix.org>2015-04-08 13:58:32 +0100
commit638be5a6b971bf961ee030d96245f296eb83e612 (patch)
tree85836d91de032ad0ed5d8323f77fcbbcd6d819b1 /synapse
parentAlso perform paranoia checks in 'on_new_user_event' (diff)
downloadsynapse-638be5a6b971bf961ee030d96245f296eb83e612.tar.xz
Factor out loops into '_discard_if_notified'
Diffstat (limited to '')
-rw-r--r--synapse/notifier.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/synapse/notifier.py b/synapse/notifier.py
index be78082021..754569ebd2 100644
--- a/synapse/notifier.py
+++ b/synapse/notifier.py
@@ -169,9 +169,7 @@ class Notifier(object):
         room_listeners = self.room_to_listeners.get(room_id, set())
 
         # Remove any 'stale' listeners.
-        for l in room_listeners.copy():
-            if l.notified():
-                room_listeners.discard(l)
+        _discard_if_notified(room_listeners)
 
         listeners = room_listeners.copy()
 
@@ -179,9 +177,7 @@ class Notifier(object):
             user_listeners = self.user_to_listeners.get(user, set())
 
             # Remove any 'stale' listeners.
-            for l in user_listeners.copy():
-                if l.notified():
-                    user_listeners.discard(l)
+            _discard_if_notified(user_listeners)
 
             listeners |= user_listeners
 
@@ -197,9 +193,7 @@ class Notifier(object):
                 )
 
                 # Remove any 'stale' listeners.
-                for l in app_listeners.copy():
-                    if l.notified():
-                        app_listeners.discard(l)
+                _discard_if_notified(app_listeners)
 
                 listeners |= app_listeners
 
@@ -255,9 +249,7 @@ class Notifier(object):
             user_listeners = self.user_to_listeners.get(user, set())
 
             # Remove any 'stale' listeners.
-            for l in user_listeners.copy():
-                if l.notified():
-                    user_listeners.discard(l)
+            _discard_if_notified(user_listeners)
 
             listeners |= user_listeners
 
@@ -265,9 +257,7 @@ class Notifier(object):
             room_listeners = self.room_to_listeners.get(room, set())
 
             # Remove any 'stale' listeners.
-            for l in room_listeners.copy():
-                if l.notified():
-                    room_listeners.discard(l)
+            _discard_if_notified(room_listeners)
 
             listeners |= room_listeners
 
@@ -470,3 +460,12 @@ class Notifier(object):
 
         for l in new_listeners:
             l.rooms.add(room_id)
+
+
+def _discard_if_notified(listener_set):
+    to_discard = set()
+    for l in listener_set:
+        if l.notified():
+            to_discard.add(l)
+
+    listener_set -= to_discard