diff options
author | Erik Johnston <erik@matrix.org> | 2016-01-25 13:36:02 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-01-25 13:36:02 +0000 |
commit | ddd25def01e3909a34c52954100763bb2a91f648 (patch) | |
tree | 3d58a9d6e9c9cfdbf6516691de7bf612cd653206 /synapse/storage/presence.py | |
parent | Merge branch 'erikj/filters' of github.com:matrix-org/synapse into develop (diff) | |
download | synapse-ddd25def01e3909a34c52954100763bb2a91f648.tar.xz |
Implement a _simple_select_many_batch
Diffstat (limited to 'synapse/storage/presence.py')
-rw-r--r-- | synapse/storage/presence.py | 35 |
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( |