mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
During room intial sync, only calculate current state once.
This commit is contained in:
parent
76c5a5c2f6
commit
d94f682a4c
@ -89,12 +89,19 @@ class Auth(object):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def check_joined_room(self, room_id, user_id):
|
def check_joined_room(self, room_id, user_id, current_state=None):
|
||||||
member = yield self.state.get_current_state(
|
if current_state:
|
||||||
room_id=room_id,
|
member = current_state.get(
|
||||||
event_type=EventTypes.Member,
|
(EventTypes.Member, user_id),
|
||||||
state_key=user_id
|
None
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
member = yield self.state.get_current_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.Member,
|
||||||
|
state_key=user_id
|
||||||
|
)
|
||||||
|
|
||||||
self._check_joined_room(member, user_id, room_id)
|
self._check_joined_room(member, user_id, room_id)
|
||||||
defer.returnValue(member)
|
defer.returnValue(member)
|
||||||
|
|
||||||
@ -102,7 +109,7 @@ class Auth(object):
|
|||||||
def check_host_in_room(self, room_id, host):
|
def check_host_in_room(self, room_id, host):
|
||||||
curr_state = yield self.state.get_current_state(room_id)
|
curr_state = yield self.state.get_current_state(room_id)
|
||||||
|
|
||||||
for event in curr_state:
|
for event in curr_state.values():
|
||||||
if event.type == EventTypes.Member:
|
if event.type == EventTypes.Member:
|
||||||
try:
|
try:
|
||||||
if UserID.from_string(event.state_key).domain != host:
|
if UserID.from_string(event.state_key).domain != host:
|
||||||
|
@ -35,6 +35,7 @@ class MessageHandler(BaseHandler):
|
|||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
super(MessageHandler, self).__init__(hs)
|
super(MessageHandler, self).__init__(hs)
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
self.state = hs.get_state_handler()
|
||||||
self.clock = hs.get_clock()
|
self.clock = hs.get_clock()
|
||||||
self.validator = EventValidator()
|
self.validator = EventValidator()
|
||||||
|
|
||||||
@ -225,7 +226,9 @@ class MessageHandler(BaseHandler):
|
|||||||
# TODO: This is duplicating logic from snapshot_all_rooms
|
# TODO: This is duplicating logic from snapshot_all_rooms
|
||||||
current_state = yield self.state_handler.get_current_state(room_id)
|
current_state = yield self.state_handler.get_current_state(room_id)
|
||||||
now = self.clock.time_msec()
|
now = self.clock.time_msec()
|
||||||
defer.returnValue([serialize_event(c, now) for c in current_state])
|
defer.returnValue(
|
||||||
|
[serialize_event(c, now) for c in current_state.values()]
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def snapshot_all_rooms(self, user_id=None, pagin_config=None,
|
def snapshot_all_rooms(self, user_id=None, pagin_config=None,
|
||||||
@ -313,7 +316,7 @@ class MessageHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
d["state"] = [
|
d["state"] = [
|
||||||
serialize_event(c, time_now, as_client_event)
|
serialize_event(c, time_now, as_client_event)
|
||||||
for c in current_state
|
for c in current_state.values()
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
logger.exception("Failed to get snapshot")
|
logger.exception("Failed to get snapshot")
|
||||||
@ -329,7 +332,14 @@ class MessageHandler(BaseHandler):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def room_initial_sync(self, user_id, room_id, pagin_config=None,
|
def room_initial_sync(self, user_id, room_id, pagin_config=None,
|
||||||
feedback=False):
|
feedback=False):
|
||||||
yield self.auth.check_joined_room(room_id, user_id)
|
current_state = yield self.state.get_current_state(
|
||||||
|
room_id=room_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield self.auth.check_joined_room(
|
||||||
|
room_id, user_id,
|
||||||
|
current_state=current_state
|
||||||
|
)
|
||||||
|
|
||||||
# TODO(paul): I wish I was called with user objects not user_id
|
# TODO(paul): I wish I was called with user objects not user_id
|
||||||
# strings...
|
# strings...
|
||||||
@ -337,13 +347,12 @@ class MessageHandler(BaseHandler):
|
|||||||
|
|
||||||
# TODO: These concurrently
|
# TODO: These concurrently
|
||||||
time_now = self.clock.time_msec()
|
time_now = self.clock.time_msec()
|
||||||
state_tuples = yield self.state_handler.get_current_state(room_id)
|
state = [
|
||||||
state = [serialize_event(x, time_now) for x in state_tuples]
|
serialize_event(x, time_now)
|
||||||
|
for x in current_state.values()
|
||||||
|
]
|
||||||
|
|
||||||
member_event = (yield self.store.get_room_member(
|
member_event = current_state.get((EventTypes.Member, user_id,))
|
||||||
user_id=user_id,
|
|
||||||
room_id=room_id
|
|
||||||
))
|
|
||||||
|
|
||||||
now_token = yield self.hs.get_event_sources().get_current_token()
|
now_token = yield self.hs.get_event_sources().get_current_token()
|
||||||
|
|
||||||
@ -360,7 +369,10 @@ class MessageHandler(BaseHandler):
|
|||||||
start_token = now_token.copy_and_replace("room_key", token[0])
|
start_token = now_token.copy_and_replace("room_key", token[0])
|
||||||
end_token = now_token.copy_and_replace("room_key", token[1])
|
end_token = now_token.copy_and_replace("room_key", token[1])
|
||||||
|
|
||||||
room_members = yield self.store.get_room_members(room_id)
|
room_members = [
|
||||||
|
m for m in current_state.values()
|
||||||
|
if m.type == EventTypes.Member
|
||||||
|
]
|
||||||
|
|
||||||
presence_handler = self.hs.get_handlers().presence_handler
|
presence_handler = self.hs.get_handlers().presence_handler
|
||||||
presence = []
|
presence = []
|
||||||
|
@ -175,9 +175,10 @@ class SyncHandler(BaseHandler):
|
|||||||
room_id, sync_config, now_token,
|
room_id, sync_config, now_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
current_state_events = yield self.state_handler.get_current_state(
|
current_state = yield self.state_handler.get_current_state(
|
||||||
room_id
|
room_id
|
||||||
)
|
)
|
||||||
|
current_state_events = current_state.values()
|
||||||
|
|
||||||
defer.returnValue(RoomSyncResult(
|
defer.returnValue(RoomSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
@ -347,9 +348,10 @@ class SyncHandler(BaseHandler):
|
|||||||
|
|
||||||
# TODO(mjark): This seems racy since this isn't being passed a
|
# TODO(mjark): This seems racy since this isn't being passed a
|
||||||
# token to indicate what point in the stream this is
|
# token to indicate what point in the stream this is
|
||||||
current_state_events = yield self.state_handler.get_current_state(
|
current_state = yield self.state_handler.get_current_state(
|
||||||
room_id
|
room_id
|
||||||
)
|
)
|
||||||
|
current_state_events = current_state.values()
|
||||||
|
|
||||||
state_at_previous_sync = yield self.get_state_at_previous_sync(
|
state_at_previous_sync = yield self.get_state_at_previous_sync(
|
||||||
room_id, since_token=since_token
|
room_id, since_token=since_token
|
||||||
@ -431,6 +433,7 @@ class SyncHandler(BaseHandler):
|
|||||||
joined = True
|
joined = True
|
||||||
|
|
||||||
if joined:
|
if joined:
|
||||||
state_delta = yield self.state_handler.get_current_state(room_id)
|
res = yield self.state_handler.get_current_state(room_id)
|
||||||
|
state_delta = res.values()
|
||||||
|
|
||||||
defer.returnValue(state_delta)
|
defer.returnValue(state_delta)
|
||||||
|
@ -76,7 +76,7 @@ class StateHandler(object):
|
|||||||
defer.returnValue(res[1].get((event_type, state_key)))
|
defer.returnValue(res[1].get((event_type, state_key)))
|
||||||
return
|
return
|
||||||
|
|
||||||
defer.returnValue(res[1].values())
|
defer.returnValue(res[1])
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def compute_event_context(self, event, old_state=None):
|
def compute_event_context(self, event, old_state=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user