[PM-43127] fix(vault): share in-flight profile fetch to avoid duplicate profile requests - #23023
Open
Tyagiquamar wants to merge 1 commit into
Open
[PM-43127] fix(vault): share in-flight profile fetch to avoid duplicate profile requests#23023Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
…requests Concurrent callers of getProfileCreationDate (the account-security and new-account nudge services during popup init) each resolved before the cache was populated and independently called apiService.getProfile(), producing two identical GET /accounts/profile requests on every popup open. fetchAndCacheProfile now shares a single in-flight promise, clearing it once settled so later calls re-fetch as before. Fixes bitwarden#22840
|
|
Collaborator
|
Thank you for your contribution! We've added this to our internal tracking system for review. Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22840
Problem
Two nudge services (
account-security-nudge.service.ts,new-account-nudge.service.ts) each callVaultProfileService.getProfileCreationDate()during popup init.fetchAndCacheProfile()only caches after the request resolves, so both concurrent calls miss the cache and independently fireGET /accounts/profile— two identical requests on every popup open (traced in the issue).Fix
Deduplicate concurrent fetches with a shared in-flight promise in
fetchAndCacheProfile()— the same patternDefaultSyncServicealready uses forsync/refreshToken. The promise is cleared infinallyonce settled, so a subsequent call after an error or completion re-fetches exactly as before. Behavior for sequential calls is unchanged.Validation
npx jest libs/angular/src/vault/services/vault-profile.service.spec.ts— 4 passed, including a new test:shares one in-flight getProfile call between concurrent callers— two concurrentgetProfileCreationDatecalls while the API call is still pending result in exactly onegetProfileinvocation; fails onmain(2 calls), passes with this fix