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

Resolve using list instead of get #3726

Merged
merged 2 commits into from
Jun 30, 2023
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
22 changes: 16 additions & 6 deletions src/FunctionAppResolver.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { getResourceGroupFromId } from "@microsoft/vscode-azext-azureutils";
import { callWithTelemetryAndErrorHandling, IActionContext, ISubscriptionContext, nonNullProp } from "@microsoft/vscode-azext-utils";
import { Site } from "@azure/arm-appservice";
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { IActionContext, ISubscriptionContext, callWithTelemetryAndErrorHandling, nonNullProp, nonNullValue } from "@microsoft/vscode-azext-utils";
import { AppResource, AppResourceResolver } from "@microsoft/vscode-azext-utils/hostapi";
import { ResolvedFunctionAppResource } from "./tree/ResolvedFunctionAppResource";
import { createWebSiteClient } from "./utils/azureClients";

export class FunctionAppResolver implements AppResourceResolver {

private siteCacheLastUpdated = 0;
private siteCache: Map<string, Site> = new Map<string, Site>();

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

const site = await client.webApps.get(rg, name);
return ResolvedFunctionAppResource.createResolvedFunctionAppResource(context, subContext, site);
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();
}

const site = this.siteCache.get(nonNullProp(resource, 'id').toLowerCase());
return ResolvedFunctionAppResource.createResolvedFunctionAppResource(context, subContext, nonNullValue(site));
});
}

Expand Down