mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Don't do unecessary db ops in presence.get_state
This commit is contained in:
parent
bc42ca121f
commit
0460406298
@ -403,6 +403,7 @@ class MessageHandler(BaseHandler):
|
|||||||
target_user=UserID.from_string(m.user_id),
|
target_user=UserID.from_string(m.user_id),
|
||||||
auth_user=auth_user,
|
auth_user=auth_user,
|
||||||
as_event=True,
|
as_event=True,
|
||||||
|
check_auth=False,
|
||||||
)
|
)
|
||||||
presence.append(member_presence)
|
presence.append(member_presence)
|
||||||
except SynapseError:
|
except SynapseError:
|
||||||
|
@ -191,24 +191,24 @@ class PresenceHandler(BaseHandler):
|
|||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@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):
|
if self.hs.is_mine(target_user):
|
||||||
visible = yield self.is_presence_visible(
|
if check_auth:
|
||||||
observer_user=auth_user,
|
visible = yield self.is_presence_visible(
|
||||||
observed_user=target_user
|
observer_user=auth_user,
|
||||||
)
|
observed_user=target_user
|
||||||
|
)
|
||||||
|
|
||||||
if not visible:
|
if not visible:
|
||||||
raise SynapseError(404, "Presence information 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 target_user in self._user_cachemap:
|
if target_user in self._user_cachemap:
|
||||||
cached_state = self._user_cachemap[target_user].get_state()
|
state = self._user_cachemap[target_user].get_state()
|
||||||
if "last_active" in cached_state:
|
else:
|
||||||
state["last_active"] = cached_state["last_active"]
|
state = yield self.store.get_presence_state(target_user.localpart)
|
||||||
|
if "mtime" in state:
|
||||||
|
del state["mtime"]
|
||||||
|
state["presence"] = state.pop("state")
|
||||||
else:
|
else:
|
||||||
# TODO(paul): Have remote server send us permissions set
|
# TODO(paul): Have remote server send us permissions set
|
||||||
state = self._get_or_offline_usercache(target_user).get_state()
|
state = self._get_or_offline_usercache(target_user).get_state()
|
||||||
|
Loading…
Reference in New Issue
Block a user