@@ -385,7 +385,7 @@ def _get_regional_authority(self, central_authority):
385385 validate_authority = False ) # The central_authority has already been validated
386386 return None
387387
388- def _build_client (self , client_credential , authority ):
388+ def _build_client (self , client_credential , authority , skip_regional_client = False ):
389389 client_assertion = None
390390 client_assertion_type = None
391391 default_headers = {
@@ -448,7 +448,8 @@ def _build_client(self, client_credential, authority):
448448 on_updating_rt = self .token_cache .update_rt )
449449
450450 regional_client = None
451- if client_credential : # Currently regional endpoint only serves some CCA flows
451+ if (client_credential # Currently regional endpoint only serves some CCA flows
452+ and not skip_regional_client ):
452453 regional_authority = self ._get_regional_authority (authority )
453454 if regional_authority :
454455 regional_configuration = {
@@ -1114,9 +1115,13 @@ def _acquire_token_silent_by_finding_specific_refresh_token(
11141115 # target=scopes, # AAD RTs are scope-independent
11151116 query = query )
11161117 logger .debug ("Found %d RTs matching %s" , len (matches ), query )
1117- client , _ = self ._build_client (self .client_credential , authority )
11181118
11191119 response = None # A distinguishable value to mean cache is empty
1120+ if not matches : # Then exit early to avoid expensive operations
1121+ return response
1122+ client , _ = self ._build_client (
1123+ # Potentially expensive if building regional client
1124+ self .client_credential , authority , skip_regional_client = True )
11201125 telemetry_context = self ._build_telemetry_context (
11211126 self .ACQUIRE_TOKEN_SILENT_ID ,
11221127 correlation_id = correlation_id , refresh_reason = refresh_reason )
0 commit comments