diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-05-07 22:40:10 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-05-07 22:40:10 +0100 |
commit | 45543028bbeb8395e8bbc5768680f6bf074d366f (patch) | |
tree | 3698fe9bc75207202d341dc4c57856e2905d0f5b /synapse | |
parent | Store presence cachemap in an ordered dict, so that the newer serials will be... (diff) | |
download | synapse-45543028bbeb8395e8bbc5768680f6bf074d366f.tar.xz |
Use the presence cachemap ordering to early-abort the iteration loop
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/handlers/presence.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 6547e0434e..601a4c6dba 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -875,10 +875,15 @@ class PresenceEventSource(object): updates = [] # TODO(paul): use a DeferredList ? How to limit concurrency. - for observed_user in cachemap.keys(): + for observed_user in reversed(cachemap.keys()): cached = cachemap[observed_user] - if cached.serial <= from_key or cached.serial > max_serial: + # Since this is ordered in descending order of serial, we can just + # stop once we've seen enough + if cached.serial <= from_key: + break + + if cached.serial > max_serial: continue if not (yield self.is_visible(observer_user, observed_user)): |