@@ -42,6 +42,8 @@ public class ApiCenterOnboardingPlugin : BaseReportingPlugin
42
42
{
43
43
private ApiCenterOnboardingPluginConfiguration _configuration = new ( ) ;
44
44
private ApiCenterClient ? _apiCenterClient ;
45
+ private Api [ ] ? _apis ;
46
+ private Dictionary < string , ApiDefinition > ? _apiDefinitionsByUrl ;
45
47
46
48
public ApiCenterOnboardingPlugin ( IPluginEvents pluginEvents , IProxyContext context , ILogger logger , ISet < UrlToWatch > urlsToWatch , IConfigurationSection ? configSection = null ) : base ( pluginEvents , context , logger , urlsToWatch , configSection )
47
49
{
@@ -74,7 +76,7 @@ public override void Register()
74
76
return ;
75
77
}
76
78
77
- Logger . LogDebug ( "Plugin {plugin} checking Azure auth ..." , Name ) ;
79
+ Logger . LogInformation ( "Plugin {plugin} connecting to Azure ..." , Name ) ;
78
80
try
79
81
{
80
82
_ = _apiCenterClient . GetAccessToken ( CancellationToken . None ) . Result ;
@@ -101,14 +103,21 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)
101
103
102
104
Debug . Assert ( _apiCenterClient is not null ) ;
103
105
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 ( ) )
106
112
{
107
113
Logger . LogInformation ( "No APIs found in API Center" ) ;
108
114
return ;
109
115
}
110
116
111
- var apiDefinitions = await apis . GetApiDefinitionsByUrl ( _apiCenterClient , Logger ) ;
117
+ if ( _apiDefinitionsByUrl is null )
118
+ {
119
+ _apiDefinitionsByUrl = await _apis . GetApiDefinitionsByUrl ( _apiCenterClient , Logger ) ;
120
+ }
112
121
113
122
var newApis = new List < ( string method , string url ) > ( ) ;
114
123
var interceptedRequests = e . RequestLogs
@@ -129,7 +138,7 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)
129
138
130
139
Logger . LogDebug ( "Processing request {method} {url}..." , method , url ) ;
131
140
132
- var apiDefinition = apiDefinitions . FirstOrDefault ( x =>
141
+ var apiDefinition = _apiDefinitionsByUrl . FirstOrDefault ( x =>
133
142
url . StartsWith ( x . Key , StringComparison . OrdinalIgnoreCase ) ) . Value ;
134
143
if ( apiDefinition is null ||
135
144
apiDefinition . Id is null )
0 commit comments