2020import msgpack
2121from unpaddedbase64 import decode_base64 , encode_base64
2222
23- from twisted .internet import defer
24-
2523from synapse .api .constants import EventTypes , JoinRules
2624from synapse .api .errors import Codes , HttpResponseException
2725from synapse .types import ThirdPartyInstanceID
28- from synapse .util .caches .descriptors import cachedInlineCallbacks
26+ from synapse .util .caches .descriptors import cached
2927from synapse .util .caches .response_cache import ResponseCache
3028
3129from ._base import BaseHandler
@@ -47,7 +45,7 @@ def __init__(self, hs):
4745 hs , "remote_room_list" , timeout_ms = 30 * 1000
4846 )
4947
50- def get_local_public_room_list (
48+ async def get_local_public_room_list (
5149 self ,
5250 limit = None ,
5351 since_token = None ,
@@ -72,7 +70,7 @@ def get_local_public_room_list(
7270 API
7371 """
7472 if not self .enable_room_list_search :
75- return defer . succeed ( {"chunk" : [], "total_room_count_estimate" : 0 })
73+ return {"chunk" : [], "total_room_count_estimate" : 0 }
7674
7775 logger .info (
7876 "Getting public room list: limit=%r, since=%r, search=%r, network=%r" ,
@@ -87,7 +85,7 @@ def get_local_public_room_list(
8785 # appservice specific lists.
8886 logger .info ("Bypassing cache as search request." )
8987
90- return self ._get_public_room_list (
88+ return await self ._get_public_room_list (
9189 limit ,
9290 since_token ,
9391 search_filter ,
@@ -96,7 +94,7 @@ def get_local_public_room_list(
9694 )
9795
9896 key = (limit , since_token , network_tuple )
99- return self .response_cache .wrap (
97+ return await self .response_cache .wrap (
10098 key ,
10199 self ._get_public_room_list ,
102100 limit ,
@@ -105,8 +103,7 @@ def get_local_public_room_list(
105103 from_federation = from_federation ,
106104 )
107105
108- @defer .inlineCallbacks
109- def _get_public_room_list (
106+ async def _get_public_room_list (
110107 self ,
111108 limit : Optional [int ] = None ,
112109 since_token : Optional [str ] = None ,
@@ -145,7 +142,7 @@ def _get_public_room_list(
145142 # we request one more than wanted to see if there are more pages to come
146143 probing_limit = limit + 1 if limit is not None else None
147144
148- results = yield self .store .get_largest_public_rooms (
145+ results = await self .store .get_largest_public_rooms (
149146 network_tuple ,
150147 search_filter ,
151148 probing_limit ,
@@ -221,52 +218,52 @@ def build_room_entry(room):
221218
222219 response ["chunk" ] = results
223220
224- response ["total_room_count_estimate" ] = yield self .store .count_public_rooms (
221+ response ["total_room_count_estimate" ] = await self .store .count_public_rooms (
225222 network_tuple , ignore_non_federatable = from_federation
226223 )
227224
228225 return response
229226
230- @cachedInlineCallbacks (num_args = 1 , cache_context = True )
231- def generate_room_entry (
227+ @cached (num_args = 1 , cache_context = True )
228+ async def generate_room_entry (
232229 self ,
233- room_id ,
234- num_joined_users ,
230+ room_id : str ,
231+ num_joined_users : int ,
235232 cache_context ,
236- with_alias = True ,
237- allow_private = False ,
238- ):
233+ with_alias : bool = True ,
234+ allow_private : bool = False ,
235+ ) -> Optional [ dict ] :
239236 """Returns the entry for a room
240237
241238 Args:
242- room_id (str) : The room's ID.
243- num_joined_users (int) : Number of users in the room.
239+ room_id: The room's ID.
240+ num_joined_users: Number of users in the room.
244241 cache_context: Information for cached responses.
245- with_alias (bool) : Whether to return the room's aliases in the result.
246- allow_private (bool) : Whether invite-only rooms should be shown.
242+ with_alias: Whether to return the room's aliases in the result.
243+ allow_private: Whether invite-only rooms should be shown.
247244
248245 Returns:
249- Deferred[dict|None]: Returns a room entry as a dictionary, or None if this
246+ Returns a room entry as a dictionary, or None if this
250247 room was determined not to be shown publicly.
251248 """
252249 result = {"room_id" : room_id , "num_joined_members" : num_joined_users }
253250
254251 if with_alias :
255- aliases = yield self .store .get_aliases_for_room (
252+ aliases = await self .store .get_aliases_for_room (
256253 room_id , on_invalidate = cache_context .invalidate
257254 )
258255 if aliases :
259256 result ["aliases" ] = aliases
260257
261- current_state_ids = yield self .store .get_current_state_ids (
258+ current_state_ids = await self .store .get_current_state_ids (
262259 room_id , on_invalidate = cache_context .invalidate
263260 )
264261
265262 if not current_state_ids :
266263 # We're not in the room, so may as well bail out here.
267264 return result
268265
269- event_map = yield self .store .get_events (
266+ event_map = await self .store .get_events (
270267 [
271268 event_id
272269 for key , event_id in current_state_ids .items ()
@@ -336,8 +333,7 @@ def generate_room_entry(
336333
337334 return result
338335
339- @defer .inlineCallbacks
340- def get_remote_public_room_list (
336+ async def get_remote_public_room_list (
341337 self ,
342338 server_name ,
343339 limit = None ,
@@ -356,7 +352,7 @@ def get_remote_public_room_list(
356352 # to a locally-filtered search if we must.
357353
358354 try :
359- res = yield self ._get_remote_list_cached (
355+ res = await self ._get_remote_list_cached (
360356 server_name ,
361357 limit = limit ,
362358 since_token = since_token ,
@@ -381,7 +377,7 @@ def get_remote_public_room_list(
381377 limit = None
382378 since_token = None
383379
384- res = yield self ._get_remote_list_cached (
380+ res = await self ._get_remote_list_cached (
385381 server_name ,
386382 limit = limit ,
387383 since_token = since_token ,
@@ -400,7 +396,7 @@ def get_remote_public_room_list(
400396
401397 return res
402398
403- def _get_remote_list_cached (
399+ async def _get_remote_list_cached (
404400 self ,
405401 server_name ,
406402 limit = None ,
@@ -412,7 +408,7 @@ def _get_remote_list_cached(
412408 repl_layer = self .hs .get_federation_client ()
413409 if search_filter :
414410 # We can't cache when asking for search
415- return repl_layer .get_public_rooms (
411+ return await repl_layer .get_public_rooms (
416412 server_name ,
417413 limit = limit ,
418414 since_token = since_token ,
@@ -428,7 +424,7 @@ def _get_remote_list_cached(
428424 include_all_networks ,
429425 third_party_instance_id ,
430426 )
431- return self .remote_response_cache .wrap (
427+ return await self .remote_response_cache .wrap (
432428 key ,
433429 repl_layer .get_public_rooms ,
434430 server_name ,
0 commit comments