@@ -358,7 +358,7 @@ def _get_regional_authority(self, central_authority):
358
358
validate_authority = False ) # The central_authority has already been validated
359
359
return None
360
360
361
- def _build_client (self , client_credential , authority ):
361
+ def _build_client (self , client_credential , authority , skip_regional_client = False ):
362
362
client_assertion = None
363
363
client_assertion_type = None
364
364
default_headers = {
@@ -417,7 +417,8 @@ def _build_client(self, client_credential, authority):
417
417
on_updating_rt = self .token_cache .update_rt )
418
418
419
419
regional_client = None
420
- if client_credential : # Currently regional endpoint only serves some CCA flows
420
+ if (client_credential # Currently regional endpoint only serves some CCA flows
421
+ and not skip_regional_client ):
421
422
regional_authority = self ._get_regional_authority (authority )
422
423
if regional_authority :
423
424
regional_configuration = {
@@ -1076,9 +1077,13 @@ def _acquire_token_silent_by_finding_specific_refresh_token(
1076
1077
# target=scopes, # AAD RTs are scope-independent
1077
1078
query = query )
1078
1079
logger .debug ("Found %d RTs matching %s" , len (matches ), query )
1079
- client , _ = self ._build_client (self .client_credential , authority )
1080
1080
1081
1081
response = None # A distinguishable value to mean cache is empty
1082
+ if not matches : # Then exit early to avoid expensive operations
1083
+ return response
1084
+ client , _ = self ._build_client (
1085
+ # Potentially expensive if building regional client
1086
+ self .client_credential , authority , skip_regional_client = True )
1082
1087
telemetry_context = self ._build_telemetry_context (
1083
1088
self .ACQUIRE_TOKEN_SILENT_ID ,
1084
1089
correlation_id = correlation_id , refresh_reason = refresh_reason )
0 commit comments