From b48ef5610e4c32f854389ad3424ed046465d8707 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 12 Aug 2022 11:41:11 +0100 Subject: [PATCH 1/3] Ensure that the response to /joined_members blocks if we have a partial state room --- synapse/handlers/message.py | 6 +++++- synapse/storage/controllers/state.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 6b0360359850..8f29ee9a8737 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -331,7 +331,11 @@ async def get_joined_members(self, requester: Requester, room_id: str) -> dict: msg="Getting joined members while not being a current member of the room is forbidden.", ) - users_with_profile = await self.store.get_users_in_room_with_profiles(room_id) + users_with_profile = ( + await self._state_storage_controller.get_users_in_room_with_profiles( + room_id + ) + ) # If this is an AS, double check that they are allowed to see the members. # This can either be because the AS user is in the room or because there diff --git a/synapse/storage/controllers/state.py b/synapse/storage/controllers/state.py index 0d480f101432..6bf68a7d7155 100644 --- a/synapse/storage/controllers/state.py +++ b/synapse/storage/controllers/state.py @@ -30,6 +30,7 @@ from synapse.api.constants import EventTypes from synapse.events import EventBase from synapse.logging.opentracing import trace +from synapse.storage.roommember import ProfileInfo from synapse.storage.state import StateFilter from synapse.storage.util.partial_state_events_tracker import ( PartialCurrentStateTracker, @@ -506,3 +507,11 @@ async def get_current_hosts_in_room(self, room_id: str) -> Set[str]: await self._partial_state_room_tracker.await_full_state(room_id) return await self.stores.main.get_current_hosts_in_room(room_id) + + async def get_users_in_room_with_profiles( + self, room_id: str + ) -> Dict[str, ProfileInfo]: + """Get the current users in the room with their profiles.""" + await self._partial_state_room_tracker.await_full_state(room_id) + + return await self.stores.main.get_users_in_room_with_profiles(room_id) From 26546f24d01e6c561aa76b2cbe4fb46e23155748 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 12 Aug 2022 11:43:30 +0100 Subject: [PATCH 2/3] Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/13514.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13514.bugfix diff --git a/changelog.d/13514.bugfix b/changelog.d/13514.bugfix new file mode 100644 index 000000000000..7498af0e472a --- /dev/null +++ b/changelog.d/13514.bugfix @@ -0,0 +1 @@ +Faster room joins: make `/joined_members` block whilst the room is partial stated. \ No newline at end of file From 206695f324ed663973d5bc9d7d74bdda1cd2d915 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 16 Aug 2022 11:43:34 +0100 Subject: [PATCH 3/3] Add comments describing partial-state behaviour --- synapse/storage/controllers/state.py | 6 +++++- synapse/storage/databases/main/roommember.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/synapse/storage/controllers/state.py b/synapse/storage/controllers/state.py index 6bf68a7d7155..0c78eb735e42 100644 --- a/synapse/storage/controllers/state.py +++ b/synapse/storage/controllers/state.py @@ -511,7 +511,11 @@ async def get_current_hosts_in_room(self, room_id: str) -> Set[str]: async def get_users_in_room_with_profiles( self, room_id: str ) -> Dict[str, ProfileInfo]: - """Get the current users in the room with their profiles.""" + """ + Get the current users in the room with their profiles. + If the room is currently partial-stated, this will block until the room has + full state. + """ await self._partial_state_room_tracker.await_full_state(room_id) return await self.stores.main.get_users_in_room_with_profiles(room_id) diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 93ff4816c804..5e5f607a14c8 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -283,6 +283,9 @@ async def get_users_in_room_with_profiles( Returns: A mapping from user ID to ProfileInfo. + + Preconditions: + - There is full state available for the room (it is not partial-stated). """ def _get_users_in_room_with_profiles(