From d98edb548af8833a7c44eded610a528e3d0515c6 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 28 Apr 2015 17:20:32 +0100 Subject: Ensure the serial returned by presence is always an integer --- synapse/handlers/presence.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'synapse/handlers/presence.py') diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 571eacd343..774df46aba 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -859,7 +859,7 @@ class PresenceEventSource(object): presence = self.hs.get_handlers().presence_handler cachemap = presence._user_cachemap clock = self.clock - latest_serial = None + latest_serial = 0 updates = [] # TODO(paul): use a DeferredList ? How to limit concurrency. @@ -872,8 +872,7 @@ class PresenceEventSource(object): if not (yield self.is_visible(observer_user, observed_user)): continue - if latest_serial is None or cached.serial > latest_serial: - latest_serial = cached.serial + latest_serial = max(cached.serial, latest_serial) updates.append(cached.make_event(user=observed_user, clock=clock)) # TODO(paul): limit @@ -882,6 +881,7 @@ class PresenceEventSource(object): if serial < from_key: break + latest_serial = max(cached.serial, serial) for u in user_ids: updates.append({ "type": "m.presence", -- cgit 1.5.1 From 0126ef7f3c1304bd920260db369628d39b4badd3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 28 Apr 2015 17:23:53 +0100 Subject: Fix typo --- synapse/handlers/presence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'synapse/handlers/presence.py') diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 774df46aba..47cfe62c82 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -881,7 +881,7 @@ class PresenceEventSource(object): if serial < from_key: break - latest_serial = max(cached.serial, serial) + latest_serial = max(latest_serial, serial) for u in user_ids: updates.append({ "type": "m.presence", -- cgit 1.5.1 From 1783c7ca920cdacb22fa8536af03f42557af9d41 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 28 Apr 2015 17:24:24 +0100 Subject: Ensure we never miss any presence updates --- synapse/handlers/presence.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'synapse/handlers/presence.py') diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 47cfe62c82..42cd528908 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -858,6 +858,9 @@ class PresenceEventSource(object): presence = self.hs.get_handlers().presence_handler cachemap = presence._user_cachemap + + max_serial = presence._user_cachemap_latest_serial + clock = self.clock latest_serial = 0 @@ -866,7 +869,7 @@ class PresenceEventSource(object): for observed_user in cachemap.keys(): cached = cachemap[observed_user] - if cached.serial <= from_key: + if cached.serial <= from_key or cached.serial > max_serial: continue if not (yield self.is_visible(observer_user, observed_user)): @@ -881,6 +884,9 @@ class PresenceEventSource(object): if serial < from_key: break + if serial > max_serial: + continue + latest_serial = max(latest_serial, serial) for u in user_ids: updates.append({ -- cgit 1.5.1