@@ -42,6 +42,8 @@ public class ApiCenterOnboardingPlugin : BaseReportingPlugin
4242{
4343 private ApiCenterOnboardingPluginConfiguration _configuration = new ( ) ;
4444 private ApiCenterClient ? _apiCenterClient ;
45+ private Api [ ] ? _apis ;
46+ private Dictionary < string , ApiDefinition > ? _apiDefinitionsByUrl ;
4547
4648 public ApiCenterOnboardingPlugin ( IPluginEvents pluginEvents , IProxyContext context , ILogger logger , ISet < UrlToWatch > urlsToWatch , IConfigurationSection ? configSection = null ) : base ( pluginEvents , context , logger , urlsToWatch , configSection )
4749 {
@@ -74,7 +76,7 @@ public override void Register()
7476 return ;
7577 }
7678
77- Logger . LogDebug ( "Plugin {plugin} checking Azure auth ..." , Name ) ;
79+ Logger . LogInformation ( "Plugin {plugin} connecting to Azure ..." , Name ) ;
7880 try
7981 {
8082 _ = _apiCenterClient . GetAccessToken ( CancellationToken . None ) . Result ;
@@ -101,14 +103,21 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)
101103
102104 Debug . Assert ( _apiCenterClient is not null ) ;
103105
104- var apis = await _apiCenterClient . GetApis ( ) ;
105- if ( apis == null || ! apis . Any ( ) )
106+ if ( _apis is null )
107+ {
108+ _apis = await _apiCenterClient . GetApis ( ) ;
109+ }
110+
111+ if ( _apis == null || ! _apis . Any ( ) )
106112 {
107113 Logger . LogInformation ( "No APIs found in API Center" ) ;
108114 return ;
109115 }
110116
111- var apiDefinitions = await apis . GetApiDefinitionsByUrl ( _apiCenterClient , Logger ) ;
117+ if ( _apiDefinitionsByUrl is null )
118+ {
119+ _apiDefinitionsByUrl = await _apis . GetApiDefinitionsByUrl ( _apiCenterClient , Logger ) ;
120+ }
112121
113122 var newApis = new List < ( string method , string url ) > ( ) ;
114123 var interceptedRequests = e . RequestLogs
@@ -129,7 +138,7 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)
129138
130139 Logger . LogDebug ( "Processing request {method} {url}..." , method , url ) ;
131140
132- var apiDefinition = apiDefinitions . FirstOrDefault ( x =>
141+ var apiDefinition = _apiDefinitionsByUrl . FirstOrDefault ( x =>
133142 url . StartsWith ( x . Key , StringComparison . OrdinalIgnoreCase ) ) . Value ;
134143 if ( apiDefinition is null ||
135144 apiDefinition . Id is null )
0 commit comments