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

WIP improve getSubscriptions performance #1852

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 12 additions & 5 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement

const allSubscriptions: AzureSubscription[] = [];
let accountCount: number; // only used for logging
let tenantCount: number = 0; // only used for logging
try {
this.suppressSignInEvents = true;
const listSubscriptionCalls: Promise<AzureSubscription[]>[] = [];

// Get the list of tenants from each account
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
accountCount = accounts.length;
for (const account of accounts) {
for (const tenant of await this.getTenants(account)) {
const tenantsInAccount = await this.getTenants(account);
tenantCount += tenantsInAccount.length;
for (const tenant of tenantsInAccount) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const tenantId = tenant.tenantId!;

Expand All @@ -118,13 +122,16 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
continue;
}

// For each tenant, get the list of subscriptions
allSubscriptions.push(...await this.getSubscriptionsForTenant(account, tenantId));
listSubscriptionCalls.push(this.getSubscriptionsForTenant(account, tenant.tenantId))
}

// list subscriptions for the home tenant
allSubscriptions.push(...await this.getSubscriptionsForTenant(account));
listSubscriptionCalls.push(this.getSubscriptionsForTenant(account))
}

allSubscriptions.push(...(await Promise.all(listSubscriptionCalls)).flat());

const endTime = Date.now();
this.logger?.debug(`auth: Got ${allSubscriptions.length} subscriptions from ${tenantCount} tenants and ${accounts.length} accounts in ${endTime - startTime}ms`);
} finally {
this.suppressSignInEvents = false;
}
Expand Down
Loading