summary refs log tree commit diff
path: root/synapse/handlers/presence.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-05-22 16:11:17 +0100
committerMark Haines <mark.haines@matrix.org>2015-05-22 16:11:17 +0100
commit1a9a9abcc73ebbd14fce0f45689e4648a71d55bc (patch)
treebf41cf9fbb090dea8a69c3d86ff9e73ee2dc54b9 /synapse/handlers/presence.py
parentMerge pull request #156 from matrix-org/erikj/join_perf (diff)
downloadsynapse-1a9a9abcc73ebbd14fce0f45689e4648a71d55bc.tar.xz
Add a cache for getting the presence list for a user
Diffstat (limited to 'synapse/handlers/presence.py')
-rw-r--r--synapse/handlers/presence.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 670c1d353f..023ad33ab0 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -521,20 +521,26 @@ class PresenceHandler(BaseHandler):
         if not self.hs.is_mine(observer_user):
             raise SynapseError(400, "User is not hosted on this Home Server")
 
-        presence = yield self.store.get_presence_list(
+        presence_list = yield self.store.get_presence_list(
             observer_user.localpart, accepted=accepted
         )
 
-        for p in presence:
-            observed_user = UserID.from_string(p.pop("observed_user_id"))
-            p["observed_user"] = observed_user
-            p.update(self._get_or_offline_usercache(observed_user).get_state())
-            if "last_active" in p:
-                p["last_active_ago"] = int(
-                    self.clock.time_msec() - p.pop("last_active")
+        results = []
+        for row in presence_list:
+            observed_user = UserID.from_string(row["observed_user_id"])
+            result = {
+                "observed_user": observed_user, "accepted": row["accepted"]
+            }
+            result.update(
+                self._get_or_offline_usercache(observed_user).get_state()
+            )
+            if "last_active" in result:
+                result["last_active_ago"] = int(
+                    self.clock.time_msec() - result.pop("last_active")
                 )
+            results.append(result)
 
-        defer.returnValue(presence)
+        defer.returnValue(results)
 
     @defer.inlineCallbacks
     @log_function