Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Avoid blocking lazy-loading /syncs during partial joins #13477

Merged
merged 12 commits into from
Aug 18, 2022
38 changes: 30 additions & 8 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,19 +964,26 @@ async def compute_state_delta(
if batch:
state_at_timeline_end = (
await self._state_storage_controller.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
batch.events[-1].event_id,
state_filter=state_filter,
await_full_state=not lazy_load_members,
richvdh marked this conversation as resolved.
Show resolved Hide resolved
)
)

state_at_timeline_start = (
await self._state_storage_controller.get_state_ids_for_event(
batch.events[0].event_id, state_filter=state_filter
batch.events[0].event_id,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)
)

else:
state_at_timeline_end = await self.get_state_at(
room_id, stream_position=now_token, state_filter=state_filter
room_id,
stream_position=now_token,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)

state_at_timeline_start = state_at_timeline_end
Expand All @@ -992,14 +999,19 @@ async def compute_state_delta(
if batch:
state_at_timeline_start = (
await self._state_storage_controller.get_state_ids_for_event(
batch.events[0].event_id, state_filter=state_filter
batch.events[0].event_id,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)
)
else:
# We can get here if the user has ignored the senders of all
# the recent events.
state_at_timeline_start = await self.get_state_at(
room_id, stream_position=now_token, state_filter=state_filter
room_id,
stream_position=now_token,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)

# for now, we disable LL for gappy syncs - see
Expand All @@ -1021,20 +1033,28 @@ async def compute_state_delta(
# is indeed the case.
assert since_token is not None
state_at_previous_sync = await self.get_state_at(
room_id, stream_position=since_token, state_filter=state_filter
room_id,
stream_position=since_token,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)

if batch:
state_at_timeline_end = (
await self._state_storage_controller.get_state_ids_for_event(
batch.events[-1].event_id, state_filter=state_filter
batch.events[-1].event_id,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)
)
else:
# We can get here if the user has ignored the senders of all
# the recent events.
state_at_timeline_end = await self.get_state_at(
room_id, stream_position=now_token, state_filter=state_filter
room_id,
stream_position=now_token,
state_filter=state_filter,
await_full_state=not lazy_load_members,
)

state_ids = _calculate_state(
Expand Down Expand Up @@ -1064,8 +1084,10 @@ async def compute_state_delta(
(EventTypes.Member, member)
for member in members_to_fetch
),
await_full_state=False,
)

# FIXME: `state_ids` may be missing memberships for partial state rooms.
# At this point, if `lazy_load_members` is enabled, `state_ids` includes
# the memberships of all event senders in the timeline. This is because we
# may not have sent the memberships in a previous sync.
Expand Down