Skip to content

Auth - avoid repeated account lookups#301712

Open
xingsy97 wants to merge 1 commit intomicrosoft:mainfrom
xingsy97:wt/auth-cache-getAllAccounts
Open

Auth - avoid repeated account lookups#301712
xingsy97 wants to merge 1 commit intomicrosoft:mainfrom
xingsy97:wt/auth-cache-getAllAccounts

Conversation

@xingsy97
Copy link
Member

Problem

AuthenticationService.getAccounts() queries all sessions via getSessions() on every call without caching, as noted by a TODO comment from @TylerLeonhardt (// TODO: Cache this).

Fix

Add a per-provider Map<string, ReadonlyArray<AuthenticationSessionAccount>> cache that is populated on first call and invalidated when:

  • The provider fires onDidChangeSessions (cache is cleared before the event is re-fired to consumers, ensuring any consumer calling getAccounts() in the event handler sees fresh data)
  • Extension session access changes for the provider (onDidChangeExtensionSessionAccess)
  • The provider is unregistered (unregisterAuthenticationProvider)

Validation

  • Cache-miss path is identical to the original code
  • Cache invalidation covers all mutation paths: session changes, access changes, and provider removal
  • Invalidation ordering ensures consumers always see consistent data in event callbacks
  • No dispose cleanup needed: cache holds pure data objects, GC handles it when the service is disposed

Copilot AI review requested due to automatic review settings March 14, 2026 14:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an in-memory, per-auth-provider cache for AuthenticationService.getAccounts() to avoid re-querying all sessions on every call, with cache invalidation wired into existing session/access lifecycle events.

Changes:

  • Introduces _accountsCache keyed by provider id and populates it on first getAccounts() call.
  • Invalidates cached entries when sessions change, when extension session access changes, and when a provider is unregistered.

@xingsy97 xingsy97 force-pushed the wt/auth-cache-getAllAccounts branch from 830eeb4 to eab87db Compare March 14, 2026 14:32
@xingsy97 xingsy97 changed the title auth: cache getAccounts results per provider Auth - avoid repeated account lookups Mar 23, 2026
Add a per-provider cache for getAccounts() to avoid redundantly
querying all sessions on every call. The cache is invalidated when:
- The provider fires onDidChangeSessions
- Extension session access changes for the provider
- The provider is unregistered

This addresses the TODO comment by TylerLeonhardt.
@xingsy97 xingsy97 force-pushed the wt/auth-cache-getAllAccounts branch from eab87db to 40b29b4 Compare March 23, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants