@@ -385,7 +385,7 @@ def _get_regional_authority(self, central_authority):
385
385
validate_authority = False ) # The central_authority has already been validated
386
386
return None
387
387
388
- def _build_client (self , client_credential , authority ):
388
+ def _build_client (self , client_credential , authority , skip_regional_client = False ):
389
389
client_assertion = None
390
390
client_assertion_type = None
391
391
default_headers = {
@@ -448,7 +448,8 @@ def _build_client(self, client_credential, authority):
448
448
on_updating_rt = self .token_cache .update_rt )
449
449
450
450
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 ):
452
453
regional_authority = self ._get_regional_authority (authority )
453
454
if regional_authority :
454
455
regional_configuration = {
@@ -1114,9 +1115,13 @@ def _acquire_token_silent_by_finding_specific_refresh_token(
1114
1115
# target=scopes, # AAD RTs are scope-independent
1115
1116
query = query )
1116
1117
logger .debug ("Found %d RTs matching %s" , len (matches ), query )
1117
- client , _ = self ._build_client (self .client_credential , authority )
1118
1118
1119
1119
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 )
1120
1125
telemetry_context = self ._build_telemetry_context (
1121
1126
self .ACQUIRE_TOKEN_SILENT_ID ,
1122
1127
correlation_id = correlation_id , refresh_reason = refresh_reason )
0 commit comments