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

Commit

Permalink
Faster room joins: Avoid blocking /keys/changes
Browse files Browse the repository at this point in the history
Part of the work for #12993.

Signed-off-by: Sean Quah <[email protected]>
  • Loading branch information
Sean Quah committed Sep 23, 2022
1 parent efd108b commit 2fc9cc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/13888.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster room joins: Avoid waiting for full state when processing `/keys/changes` requests.
7 changes: 5 additions & 2 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ async def get_user_ids_changed(
possibly_changed = set(changed)
possibly_left = set()
for room_id in rooms_changed:
current_state_ids = await self._state_storage.get_current_state_ids(room_id)
current_state_ids = await self._state_storage.get_current_state_ids(
room_id, await_full_state=False
)

# The user may have left the room
# TODO: Check if they actually did or if we were just invited.
Expand Down Expand Up @@ -234,7 +236,8 @@ async def get_user_ids_changed(

# mapping from event_id -> state_dict
prev_state_ids = await self._state_storage.get_state_ids_for_events(
event_ids
event_ids,
await_full_state=False,
)

# Check if we've joined the room? If so we just blindly add all the users to
Expand Down
7 changes: 6 additions & 1 deletion synapse/storage/controllers/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ async def get_current_state_ids(
self,
room_id: str,
state_filter: Optional[StateFilter] = None,
await_full_state: bool = True,
on_invalidate: Optional[Callable[[], None]] = None,
) -> StateMap[str]:
"""Get the current state event ids for a room based on the
Expand All @@ -419,13 +420,17 @@ async def get_current_state_ids(
room_id: The room to get the state IDs of. state_filter: The state
filter used to fetch state from the
database.
await_full_state: if true, will block if we do not yet have complete
state for the room.
on_invalidate: Callback for when the `get_current_state_ids` cache
for the room gets invalidated.
Returns:
The current state of the room.
"""
if not state_filter or state_filter.must_await_full_state(self._is_mine_id):
if await_full_state and (
not state_filter or state_filter.must_await_full_state(self._is_mine_id)
):
await self._partial_state_room_tracker.await_full_state(room_id)

if state_filter and not state_filter.is_full():
Expand Down

0 comments on commit 2fc9cc6

Please sign in to comment.