diff options
author | Erik Johnston <erik@matrix.org> | 2015-06-16 16:59:38 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-06-16 16:59:38 +0100 |
commit | 04604062984a6dc27174fa42e4c9f91fbe7b0c42 (patch) | |
tree | 34ce88b86ad325d99b453a0f8c82faab1b80fc96 /synapse | |
parent | Merge pull request #185 from matrix-org/erikj/listeners_config (diff) | |
download | synapse-04604062984a6dc27174fa42e4c9f91fbe7b0c42.tar.xz |
Don't do unecessary db ops in presence.get_state
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/handlers/message.py | 1 | ||||
-rw-r--r-- | synapse/handlers/presence.py | 28 |
2 files changed, 15 insertions, 14 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 867fdbefb0..1ed9e961f1 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -403,6 +403,7 @@ class MessageHandler(BaseHandler): target_user=UserID.from_string(m.user_id), auth_user=auth_user, as_event=True, + check_auth=False, ) presence.append(member_presence) except SynapseError: diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 023ad33ab0..7c03198313 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -191,24 +191,24 @@ class PresenceHandler(BaseHandler): defer.returnValue(False) @defer.inlineCallbacks - def get_state(self, target_user, auth_user, as_event=False): + def get_state(self, target_user, auth_user, as_event=False, check_auth=True): if self.hs.is_mine(target_user): - visible = yield self.is_presence_visible( - observer_user=auth_user, - observed_user=target_user - ) + if check_auth: + visible = yield self.is_presence_visible( + observer_user=auth_user, + observed_user=target_user + ) - if not visible: - raise SynapseError(404, "Presence information not visible") - state = yield self.store.get_presence_state(target_user.localpart) - if "mtime" in state: - del state["mtime"] - state["presence"] = state.pop("state") + if not visible: + raise SynapseError(404, "Presence information not visible") if target_user in self._user_cachemap: - cached_state = self._user_cachemap[target_user].get_state() - if "last_active" in cached_state: - state["last_active"] = cached_state["last_active"] + state = self._user_cachemap[target_user].get_state() + else: + state = yield self.store.get_presence_state(target_user.localpart) + if "mtime" in state: + del state["mtime"] + state["presence"] = state.pop("state") else: # TODO(paul): Have remote server send us permissions set state = self._get_or_offline_usercache(target_user).get_state() |