Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a listTask so the cache works for all resolves #2662

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/WebAppResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ export class WebAppResolver implements AppResourceResolver {

private siteCacheLastUpdated = 0;
private siteCache: Map<string, Site> = new Map<string, Site>();
private listWebAppsTask: Promise<void> | undefined;

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

if (this.siteCacheLastUpdated < Date.now() - 1000 * 3) {
this.siteCache.clear();
const sites = await uiUtils.listAllIterator(client.webApps.list());
sites.forEach(site => this.siteCache.set(nonNullProp(site, 'id').toLowerCase(), site));
this.siteCacheLastUpdated = Date.now();
this.listWebAppsTask = new Promise((resolve, reject) => {
this.siteCache.clear();
uiUtils.listAllIterator(client.webApps.list()).then((sites) => {
for (const site of sites) {
this.siteCache.set(nonNullProp(site, 'id').toLowerCase(), site);
}
resolve();
})
.catch((reason) => {
reject(reason);
});
});
}

await this.listWebAppsTask;
const site = this.siteCache.get(nonNullProp(resource, 'id').toLowerCase());
return new ResolvedWebAppResource(subContext, nonNullValue(site));
});
Expand Down
Loading