summary refs log tree commit diff
path: root/synapse/storage/presence.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-01-25 16:30:36 +0000
committerErik Johnston <erik@matrix.org>2016-01-25 16:30:36 +0000
commit8431f62ebb40ee45a23f3f1775b7cdf8614d7145 (patch)
treef36c04de71921adbfc2ddd8b0dcd658889d557bc /synapse/storage/presence.py
parentMerge pull request #527 from matrix-org/erikj/push_cache (diff)
parentGuard against empty iterables (diff)
downloadsynapse-8431f62ebb40ee45a23f3f1775b7cdf8614d7145.tar.xz
Merge pull request #525 from matrix-org/erikj/select_many
Implement a `_simple_select_many_batch`
Diffstat (limited to 'synapse/storage/presence.py')
-rw-r--r--synapse/storage/presence.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py
index 1095d52ace..9b3aecaf8c 100644
--- a/synapse/storage/presence.py
+++ b/synapse/storage/presence.py
@@ -48,24 +48,25 @@ class PresenceStore(SQLBaseStore):
             desc="get_presence_state",
         )
 
-    @cachedList(get_presence_state.cache, list_name="user_localparts")
+    @cachedList(get_presence_state.cache, list_name="user_localparts",
+                inlineCallbacks=True)
     def get_presence_states(self, user_localparts):
-        def f(txn):
-            results = {}
-            for user_localpart in user_localparts:
-                res = self._simple_select_one_txn(
-                    txn,
-                    table="presence",
-                    keyvalues={"user_id": user_localpart},
-                    retcols=["state", "status_msg", "mtime"],
-                    allow_none=True,
-                )
-                if res:
-                    results[user_localpart] = res
-
-            return results
-
-        return self.runInteraction("get_presence_states", f)
+        rows = yield self._simple_select_many_batch(
+            table="presence",
+            column="user_id",
+            iterable=user_localparts,
+            retcols=("user_id", "state", "status_msg", "mtime",),
+            desc="get_presence_states",
+        )
+
+        defer.returnValue({
+            row["user_id"]: {
+                "state": row["state"],
+                "status_msg": row["status_msg"],
+                "mtime": row["mtime"],
+            }
+            for row in rows
+        })
 
     def set_presence_state(self, user_localpart, new_state):
         res = self._simple_update_one(