Add per-tree cache invalidation to fix #1413#1416
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes regressions introduced in #1383 by updating the cache-invalidation mechanism so cache clears are scoped per tree (Azure Resources, Accounts & Tenants, Focus), and by restoring an explicit cache-clear + refresh when subscription selection changes.
Changes:
- Replace shared one-shot cache-clear boolean with per-tree cache-clear flags keyed by
TreeViewId(azure | tenant | focus). - Update Azure, Tenants, and Focus tree data providers to consume the per-tree cache-clear flag.
- Restore explicit cache-clear +
refreshAzureTree()after updating the selected subscriptions setting.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/extensionVariables.ts | Introduces TreeViewId and per-tree cache-clear flag storage + APIs. |
| src/tree/azure/AzureResourceTreeDataProvider.ts | Consumes the cache-clear flag for the Azure tree via consumeClearCacheFlag('azure'). |
| src/tree/tenants/TenantResourceTreeDataProvider.ts | Consumes the cache-clear flag for the Tenants tree via consumeClearCacheFlag('tenant'). |
| src/tree/azure/FocusViewTreeDataProvider.ts | Consumes the cache-clear flag for the Focus tree via consumeClearCacheFlag('focus'). |
| src/commands/accounts/selectSubscriptions.ts | Re-adds explicit cache-clear + Azure tree refresh after subscription selection updates. |
| src/commands/accounts/logIn.ts | Clears cache + refreshes Azure and Tenants trees after sign-in using per-tree flags. |
| src/commands/registerCommands.ts | Updates refresh/sign-in commands to set per-tree cache-clear flags. |
| src/commands/sovereignCloud/configureSovereignCloud.ts | Clears cache + refreshes Azure and Tenants views after sovereign cloud changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ext.setClearCacheOnNextLoad('azure'); | ||
| ext.actions.refreshAzureTree(); // Refresh now that sign in is complete | ||
| ext.setClearCacheOnNextLoad('tenant'); | ||
| ext.actions.refreshTenantTree(); // Refresh now that sign in is complete |
There was a problem hiding this comment.
After sign-in you clear/refresh Azure and Tenants, but the Focus view uses its own subscription provider + per-tree cache flag (consumeClearCacheFlag('focus')). If the Focus view was previously loaded, it can still refresh using stale cached subscriptions unless you also set the Focus cache-clear flag (and refresh the focus tree if appropriate).
| ext.actions.refreshTenantTree(); // Refresh now that sign in is complete | |
| ext.actions.refreshTenantTree(); // Refresh now that sign in is complete | |
| ext.setClearCacheOnNextLoad('focus'); | |
| ext.actions.refreshFocusTree?.(); // Refresh Focus view to ensure it uses fresh subscriptions |
| ext.setClearCacheOnNextLoad('azure'); | ||
| ext.actions.refreshAzureTree(); | ||
| ext.setClearCacheOnNextLoad('tenant'); | ||
| ext.actions.refreshTenantTree(); |
There was a problem hiding this comment.
This command clears/refreshes Azure Resources and Accounts & Tenants, but the Focus view has an independent subscription cache (per-tree cache flag). If users have a focused group, the Focus view may continue showing resources from the previous cloud unless you also clear the Focus cache (and refresh the Focus tree).
| ext.actions.refreshTenantTree(); | |
| ext.actions.refreshTenantTree(); | |
| ext.setClearCacheOnNextLoad('focus'); | |
| ext.actions.refreshFocusTree(); |
| registerCommand('azureTenantsView.signInToTenant', async (_context, node: TenantTreeItem) => { | ||
| await (await ext.subscriptionProviderFactory()).signIn(node); | ||
| ext.setClearCacheOnNextLoad(); | ||
| ext.setClearCacheOnNextLoad('tenant'); | ||
| ext.actions.refreshTenantTree(); | ||
| ext.setClearCacheOnNextLoad('azure'); | ||
| ext.actions.refreshAzureTree(); |
There was a problem hiding this comment.
After signing in to a tenant, caches are cleared for the Tenants and Azure trees but not for the Focus view. Since each tree now has an independent cache-clear flag, the Focus view can refresh on onRefreshSuggested yet still read stale cached subscriptions unless you also set setClearCacheOnNextLoad('focus') (and refresh the focus tree when needed).
| registerCommand('azureResourceGroups.signInToTenant', async () => { | ||
| await signInToTenant(await ext.subscriptionProviderFactory()); | ||
| ext.setClearCacheOnNextLoad(); | ||
| ext.setClearCacheOnNextLoad('tenant'); | ||
| ext.actions.refreshTenantTree(); | ||
| ext.setClearCacheOnNextLoad('azure'); | ||
| ext.actions.refreshAzureTree(); |
There was a problem hiding this comment.
Same as above for the command-palette azureResourceGroups.signInToTenant: it clears/refreshes tenant+azure trees but not focus. With per-tree cache flags, consider also clearing the Focus view cache (and refreshing focus) so all views reflect the new tenant auth state consistently.
930efba to
c496bde
Compare
c496bde to
ed3a9d7
Compare
ed3a9d7 to
c956267
Compare
Replace the shared one-shot cache-clear boolean with per-tree flags (azure, tenant, focus). The old boolean was consumed by whichever tree loaded first, leaving other trees to read stale cached data. - Convert clearCacheOnNextLoadFlag boolean to per-tree flag map - setClearCacheOnNextLoad/consumeClearCacheFlag now take a TreeViewId - Add cache-clear per tree in signInToTenant and configureSovereignCloud - Include Focus view in cache-clear + refresh for sign-in, sign-in-to- tenant, and sovereign cloud commands - Set cache-clear flag before updating subscription setting so the provider-triggered refresh already sees noCache: true - Tenant tree now refreshes on any reason except subscriptionFilterChange, making it forward-compatible with new reasons (e.g. cloudChange) Fixes #1413 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c956267 to
bff1bfd
Compare
Bug Fix
#1413 — Accounts & Tenants view does not auto-refresh after adding a second account
The cache-clear mechanism was a shared one-shot boolean. Whichever tree called
consumeClearCacheFlag()first gotnoCache: true; subsequent trees gotfalseand loaded from stale cache (missing the newly added account).Fix
Replace the shared boolean with per-tree flags (
azure | tenant | focus). Each tree has its own independent flag via aTreeViewId-keyed record, so:Additional improvements
onDidChangeConfiguration) already seesnoCache: true— avoids a redundant second refreshonRefreshSuggestedreason exceptsubscriptionFilterChange, making it forward-compatible with new reasons (e.g.cloudChangefrom auth: Watch sovereign cloud config and fire onRefreshSuggested vscode-azuretools#2248)Root cause
Regression introduced by PR #1383 ("Performance improvements", commit b76bfd8).
Fixes #1413