mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 13:23:49 +01:00
Add batched version of store.get_presence_state
This commit is contained in:
parent
f9d4da7f45
commit
47abebfd6d
1 changed files with 19 additions and 1 deletions
|
@ -14,7 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from ._base import SQLBaseStore
|
from ._base import SQLBaseStore
|
||||||
from synapse.util.caches.descriptors import cached
|
from synapse.util.caches.descriptors import cached, cachedList
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ class PresenceStore(SQLBaseStore):
|
||||||
desc="has_presence_state",
|
desc="has_presence_state",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cached()
|
||||||
def get_presence_state(self, user_localpart):
|
def get_presence_state(self, user_localpart):
|
||||||
return self._simple_select_one(
|
return self._simple_select_one(
|
||||||
table="presence",
|
table="presence",
|
||||||
|
@ -44,6 +45,23 @@ class PresenceStore(SQLBaseStore):
|
||||||
desc="get_presence_state",
|
desc="get_presence_state",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cachedList(get_presence_state.cache, list_name="user_localparts")
|
||||||
|
def get_presence_states(self, user_localparts):
|
||||||
|
def f(txn):
|
||||||
|
results = {}
|
||||||
|
for user_localpart in user_localparts:
|
||||||
|
results[user_localpart] = self._simple_select_one_txn(
|
||||||
|
txn,
|
||||||
|
table="presence",
|
||||||
|
keyvalues={"user_id": user_localpart},
|
||||||
|
retcols=["state", "status_msg", "mtime"],
|
||||||
|
desc="get_presence_state",
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
return self.runInteraction("get_presence_states", f)
|
||||||
|
|
||||||
def set_presence_state(self, user_localpart, new_state):
|
def set_presence_state(self, user_localpart, new_state):
|
||||||
return self._simple_update_one(
|
return self._simple_update_one(
|
||||||
table="presence",
|
table="presence",
|
||||||
|
|
Loading…
Reference in a new issue