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

Use the room type from stats in hierarchy response. #14263

Merged
merged 4 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14263.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of the `/hierarchy` endpoint.
14 changes: 5 additions & 9 deletions synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import attr

from synapse.api.constants import (
EventContentFields,
EventTypes,
HistoryVisibility,
JoinRules,
Expand Down Expand Up @@ -701,13 +700,6 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic
# there should always be an entry
assert stats is not None, "unable to retrieve stats for %s" % (room_id,)

current_state_ids = await self._storage_controllers.state.get_current_state_ids(
room_id
)
Comment on lines -704 to -706
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach might have been to use a StateFilter to only fetch the create event.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but you're still doing additional queries you don't need!

create_event = await self._store.get_event(
current_state_ids[(EventTypes.Create, "")]
)
Comment on lines -704 to -709
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also could gate this on whether the background update finished?


entry = {
"room_id": stats["room_id"],
"name": stats["name"],
Expand All @@ -720,7 +712,7 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic
stats["history_visibility"] == HistoryVisibility.WORLD_READABLE
),
"guest_can_join": stats["guest_access"] == "can_join",
"room_type": create_event.content.get(EventContentFields.ROOM_TYPE),
"room_type": stats["room_type"],
clokep marked this conversation as resolved.
Show resolved Hide resolved
}

if self._msc3266_enabled:
Expand All @@ -730,7 +722,11 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic
# Federation requests need to provide additional information so the
# requested server is able to filter the response appropriately.
if for_federation:
current_state_ids = (
await self._storage_controllers.state.get_current_state_ids(room_id)
)
room_version = await self._store.get_room_version(room_id)

if await self._event_auth_handler.has_restricted_join_rules(
current_state_ids, room_version
):
Expand Down