mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 06:29:27 -05:00
Merge pull request #189 from matrix-org/erikj/room_init_sync
Improve room init sync speed.
This commit is contained in:
commit
9bf61ef97b
@ -380,15 +380,6 @@ class MessageHandler(BaseHandler):
|
|||||||
if limit is None:
|
if limit is None:
|
||||||
limit = 10
|
limit = 10
|
||||||
|
|
||||||
messages, token = yield self.store.get_recent_events_for_room(
|
|
||||||
room_id,
|
|
||||||
limit=limit,
|
|
||||||
end_token=now_token.room_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
start_token = now_token.copy_and_replace("room_key", token[0])
|
|
||||||
end_token = now_token.copy_and_replace("room_key", token[1])
|
|
||||||
|
|
||||||
room_members = [
|
room_members = [
|
||||||
m for m in current_state.values()
|
m for m in current_state.values()
|
||||||
if m.type == EventTypes.Member
|
if m.type == EventTypes.Member
|
||||||
@ -396,19 +387,38 @@ class MessageHandler(BaseHandler):
|
|||||||
]
|
]
|
||||||
|
|
||||||
presence_handler = self.hs.get_handlers().presence_handler
|
presence_handler = self.hs.get_handlers().presence_handler
|
||||||
presence = []
|
|
||||||
for m in room_members:
|
@defer.inlineCallbacks
|
||||||
try:
|
def get_presence():
|
||||||
member_presence = yield presence_handler.get_state(
|
presence_defs = yield defer.DeferredList(
|
||||||
target_user=UserID.from_string(m.user_id),
|
[
|
||||||
auth_user=auth_user,
|
presence_handler.get_state(
|
||||||
as_event=True,
|
target_user=UserID.from_string(m.user_id),
|
||||||
)
|
auth_user=auth_user,
|
||||||
presence.append(member_presence)
|
as_event=True,
|
||||||
except SynapseError:
|
check_auth=False,
|
||||||
logger.exception(
|
)
|
||||||
"Failed to get member presence of %r", m.user_id
|
for m in room_members
|
||||||
|
],
|
||||||
|
consumeErrors=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue([p for success, p in presence_defs if success])
|
||||||
|
|
||||||
|
presence, (messages, token) = yield defer.gatherResults(
|
||||||
|
[
|
||||||
|
get_presence(),
|
||||||
|
self.store.get_recent_events_for_room(
|
||||||
|
room_id,
|
||||||
|
limit=limit,
|
||||||
|
end_token=now_token.room_key,
|
||||||
)
|
)
|
||||||
|
],
|
||||||
|
consumeErrors=True,
|
||||||
|
).addErrback(unwrapFirstError)
|
||||||
|
|
||||||
|
start_token = now_token.copy_and_replace("room_key", token[0])
|
||||||
|
end_token = now_token.copy_and_replace("room_key", token[1])
|
||||||
|
|
||||||
time_now = self.clock.time_msec()
|
time_now = self.clock.time_msec()
|
||||||
|
|
||||||
|
@ -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