@@ -111,7 +111,15 @@ def __init__(self, hs: "HomeServer"):
111111 # If a user tries to fetch the same page multiple times in quick succession,
112112 # only process the first attempt and return its result to subsequent requests.
113113 self ._pagination_response_cache : ResponseCache [
114- Tuple [str , str , bool , Optional [int ], Optional [int ], Optional [str ]]
114+ Tuple [
115+ str ,
116+ str ,
117+ bool ,
118+ Optional [int ],
119+ Optional [int ],
120+ Optional [str ],
121+ Optional [Tuple [str , ...]],
122+ ]
115123 ] = ResponseCache (
116124 hs .get_clock (),
117125 "get_room_hierarchy" ,
@@ -126,6 +134,7 @@ async def get_room_hierarchy(
126134 max_depth : Optional [int ] = None ,
127135 limit : Optional [int ] = None ,
128136 from_token : Optional [str ] = None ,
137+ remote_room_hosts : Optional [Tuple [str , ...]] = None ,
129138 ) -> JsonDict :
130139 """
131140 Implementation of the room hierarchy C-S API.
@@ -143,6 +152,9 @@ async def get_room_hierarchy(
143152 limit: An optional limit on the number of rooms to return per
144153 page. Must be a positive integer.
145154 from_token: An optional pagination token.
155+ remote_room_hosts: An optional list of remote homeserver server names. If defined,
156+ each host will be used to try and fetch the room hierarchy. Must be a tuple so
157+ that it can be hashed by the `RoomSummaryHandler._pagination_response_cache`.
146158
147159 Returns:
148160 The JSON hierarchy dictionary.
@@ -162,6 +174,7 @@ async def get_room_hierarchy(
162174 max_depth ,
163175 limit ,
164176 from_token ,
177+ remote_room_hosts ,
165178 ),
166179 self ._get_room_hierarchy ,
167180 requester .user .to_string (),
@@ -170,6 +183,7 @@ async def get_room_hierarchy(
170183 max_depth ,
171184 limit ,
172185 from_token ,
186+ remote_room_hosts ,
173187 )
174188
175189 async def _get_room_hierarchy (
@@ -180,6 +194,7 @@ async def _get_room_hierarchy(
180194 max_depth : Optional [int ] = None ,
181195 limit : Optional [int ] = None ,
182196 from_token : Optional [str ] = None ,
197+ remote_room_hosts : Optional [Tuple [str , ...]] = None ,
183198 ) -> JsonDict :
184199 """See docstring for SpaceSummaryHandler.get_room_hierarchy."""
185200
@@ -199,7 +214,7 @@ async def _get_room_hierarchy(
199214
200215 if not local_room :
201216 room_hierarchy = await self ._summarize_remote_room_hierarchy (
202- _RoomQueueEntry (requested_room_id , ()),
217+ _RoomQueueEntry (requested_room_id , remote_room_hosts or ()),
203218 False ,
204219 )
205220 root_room_entry = room_hierarchy [0 ]
@@ -240,7 +255,7 @@ async def _get_room_hierarchy(
240255 processed_rooms = set (pagination_session ["processed_rooms" ])
241256 else :
242257 # The queue of rooms to process, the next room is last on the stack.
243- room_queue = [_RoomQueueEntry (requested_room_id , ())]
258+ room_queue = [_RoomQueueEntry (requested_room_id , remote_room_hosts or ())]
244259
245260 # Rooms we have already processed.
246261 processed_rooms = set ()
0 commit comments