From 18e873669647c96ecb35b6fa7d6998e0a7012d06 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 24 Mar 2023 18:27:13 -0400 Subject: [PATCH] Return a single dictionary of all results. --- synapse/handlers/appservice.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 6477d7979103..e75e380b24c4 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -18,6 +18,7 @@ Dict, Iterable, List, + Mapping, Optional, Tuple, Union, @@ -901,8 +902,8 @@ async def claim_e2e_one_time_keys( return claimed_keys, missing async def query_keys( - self, query: Dict[str, Optional[ List[str]]] - ) -> Iterable[Dict[str, Dict[str, Dict[str, JsonDict]]]]: + self, query: Mapping[str, Optional[List[str]]] + ) -> Dict[str, Dict[str, Dict[str, JsonDict]]]: """Query application services for device keys. Args: @@ -922,7 +923,9 @@ async def query_keys( # Find the associated appservice. for service in services: if service.is_exclusive_user(user_id): - query_by_appservice.setdefault(service.id, {})[user_id] = device_ids + query_by_appservice.setdefault(service.id, {})[user_id] = ( + device_ids or [] + ) continue # Query each service in parallel. @@ -941,10 +944,11 @@ async def query_keys( ) ) - # Patch together the results. - key_queries: List[Dict[str, Dict[str, Dict[str, JsonDict]]]] = [] + # Patch together the results. Since the appservices are exclusive they + # can just be splatted together. + key_queries: Dict[str, Dict[str, Dict[str, JsonDict]]] = {} for success, result in results: if success: - key_queries.append(result) + key_queries.update(result) return key_queries