Skip to content

Commit ff6c47d

Browse files
Fix resolver caching (#4239)
* Fix resolver caching
1 parent 14e87cd commit ff6c47d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/FunctionAppResolver.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,35 @@ type Site20231201 = Site & { isFlex?: boolean };
1111
export class FunctionAppResolver implements AppResourceResolver {
1212
private siteCacheLastUpdated = 0;
1313
private siteCache: Map<string, Site20231201> = new Map<string, Site20231201>();
14+
private listFunctionAppsTask: Promise<void> | undefined;
1415

1516
public async resolveResource(subContext: ISubscriptionContext, resource: AppResource): Promise<ResolvedFunctionAppResource | ResolvedContainerizedFunctionAppResource | undefined> {
1617
return await callWithTelemetryAndErrorHandling('resolveResource', async (context: IActionContext) => {
1718
const client = await createWebSiteClient({ ...context, ...subContext });
1819

1920
if (this.siteCacheLastUpdated < Date.now() - 1000 * 3) {
20-
this.siteCache.clear();
21-
const sites = await uiUtils.listAllIterator(client.webApps.list());
22-
for (const site of sites) {
23-
this.siteCache.set(resource.id, site);
24-
this.siteCacheLastUpdated = Date.now();
25-
}
21+
this.siteCacheLastUpdated = Date.now();
22+
this.listFunctionAppsTask = new Promise((resolve, reject) => {
23+
this.siteCache.clear();
24+
uiUtils.listAllIterator(client.webApps.list()).then((sites) => {
25+
for (const site of sites) {
26+
this.siteCache.set(nonNullProp(site, 'id').toLowerCase(), site);
27+
}
28+
resolve();
29+
})
30+
.catch((reason) => {
31+
reject(reason);
32+
});
33+
});
2634
}
35+
await this.listFunctionAppsTask;
2736

2837
let site = this.siteCache.get(nonNullProp(resource, 'id').toLowerCase());
2938
// check for required properties that sometime don't exist in the LIST operation
3039
if (!site || !site.defaultHostName) {
3140
// if this required property doesn't exist, try getting the full site payload
3241
site = await client.webApps.get(getResourceGroupFromId(resource.id), resource.name);
33-
this.siteCache.set(resource.id, site);
42+
this.siteCache.set(resource.id.toLowerCase(), site);
3443
}
3544

3645
if (nonNullValueAndProp(site, 'kind') === 'functionapp,linux,container,azurecontainerapps') {

0 commit comments

Comments
 (0)