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

feat: cache results of getEnv() #857

Merged
merged 3 commits into from Dec 23, 2019
Merged

feat: cache results of getEnv() #857

merged 3 commits into from Dec 23, 2019

Conversation

bcoe
Copy link
Contributor

@bcoe bcoe commented Dec 23, 2019

This fixes failing tests caused by introducing caching to gcp-metadata.

Taking a page fro gcp-metadata, this now also caches the promise returned by getEnv rather than its value, such that multiple libraries instantiated at the same time will not result in multiple enqueued promises.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 23, 2019
@codecov
Copy link

codecov bot commented Dec 23, 2019

Codecov Report

Merging #857 into master will increase coverage by 0.16%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #857      +/-   ##
==========================================
+ Coverage    85.2%   85.37%   +0.16%     
==========================================
  Files          17       17              
  Lines         960      964       +4     
  Branches      215      215              
==========================================
+ Hits          818      823       +5     
  Misses         85       85              
+ Partials       57       56       -1
Impacted Files Coverage Δ
src/auth/envDetect.ts 93.75% <86.66%> (+4.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1147733...a8bb81c. Read the comment docs.

}

async function getEnvMemoized(): Promise<GCPEnv> {
let env: GCPEnv | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just let env = GCPEnv.NONE; and remove the last else?

@bcoe bcoe merged commit d4545a9 into master Dec 23, 2019
@bcoe bcoe deleted the memoize-get-env branch December 23, 2019 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants