Filter unselected tenants before hitting maximumTenants limit#1406
Filter unselected tenants before hitting maximumTenants limit#1406alexweininger merged 3 commits intomainfrom
Conversation
The Accounts & Tenants view checkbox state (stored as 'unselectedTenants' in globalState) was not being applied during subscription loading. The auth package's getTenantFilters() only reads from selectedSubscriptions config, so unchecked tenants still counted toward the maximumTenants limit (default 10), silently preventing selected tenants from being processed. This creates a ResourceGroupsSubscriptionProvider subclass that overrides getTenantsForAccount() to additionally filter out tenants unchecked in the Accounts & Tenants view, ensuring only selected tenants consume slots in the maximumTenants budget. Fixes #1387 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses missing subscriptions for users with many tenants by filtering out tenants unchecked in the Accounts & Tenants view so they don’t consume the maximumTenants budget during subscription loading.
Changes:
- Added a
VSCodeAzureSubscriptionProvidersubclass to apply additional tenant filtering based on Accounts & Tenants view state. - Updated provider factory/creation to instantiate and cache the new subclass.
- Added logging when tenant filtering reduces the tenant set.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses PR feedback by extracting isTenantFilteredOut, getUnselectedTenants, setUnselectedTenants, and getKeyForTenant from the tree-layer registerTenantTree module into src/utils/tenantSelection.ts. This eliminates the coupling between the service-layer subscription provider and the tree/view module. Also keeps the factory return type as the base VSCodeAzureSubscriptionProvider to avoid leaking the concrete subclass type to consumers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aligns tenant filtering in subscription discovery with the Accounts & Tenants checkbox state by centralizing tenant-selection persistence and applying that selection when enumerating tenants for an account, preventing unselected tenants from consuming the maximumTenants budget.
Changes:
- Added
src/utils/tenantSelection.tsto centralizeunselectedTenantsglobalState logic (getKeyForTenant,getUnselectedTenants,setUnselectedTenants,isTenantFilteredOut). - Updated the tenant tree and subscription-selection flows to import tenant-selection helpers from the new utility module.
- Introduced a
ResourceGroupsSubscriptionProvidersubclass to filter out unchecked tenants duringgetTenantsForAccount()when filtering is enabled.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/tenantSelection.ts | New shared utility for persisting/reading tenant checkbox selection state and evaluating whether a tenant is filtered out. |
| src/tree/tenants/registerTenantTree.ts | Switches tenant checkbox persistence to use the new tenantSelection utility (removes duplicated local helpers). |
| src/tree/tenants/TenantResourceTreeDataProvider.ts | Updates import to use the new shared isTenantFilteredOut. |
| src/services/VSCodeAzureSubscriptionProvider.ts | Wraps the azureauth subscription provider to exclude unchecked tenants during tenant enumeration when filtering is enabled. |
| src/commands/accounts/selectSubscriptions.ts | Updates import to use the new shared isTenantFilteredOut. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
this is a performance bug too! |
Problem
Users with many tenants (e.g., 33) see missing subscriptions because the
maximumTenantslimit (default 10) silently drops tenants — even when only a few are selected in the Accounts & Tenants view.Root cause: The Accounts & Tenants view stores unselected tenants in
globalState(unselectedTenants), but the auth package'sgetTenantFilters()only reads fromselectedSubscriptionsconfig. These are two different filtering mechanisms, and the tenant view checkbox state was never communicated to the subscription loading path. So all 33 tenants were returned, 10 were processed (many failing auth), and the user's actual tenant was silently skipped.Fix
Creates a
ResourceGroupsSubscriptionProvidersubclass that overridesgetTenantsForAccount()to additionally filter out tenants unchecked in the Accounts & Tenants view. This ensures only selected tenants consume slots in themaximumTenantsbudget.Before: User with 33 tenants, 1 selected → all 33 returned → limit of 10 hit → selected tenant likely skipped → 0 subscriptions shown.
After: User with 33 tenants, 1 selected → 1 tenant returned → well under limit → subscriptions loaded correctly.
Fixes #1387