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

refactor(utils): generate unique id only when needed #915

Merged
merged 1 commit into from
Apr 5, 2022
Merged

refactor(utils): generate unique id only when needed #915

merged 1 commit into from
Apr 5, 2022

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented Apr 4, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

uuidv4() is being called even if it's not used.

What is the new behavior?

Inlines the uuid() call to rely on JS short circuit on OR operation to generate the uuid v4 only if the factory key was not provided. The factory.KEY will always be defined for those that are using registerAs, thus they can avoid the computation of uuidv4()

$ node
> const foo = () => {}
> const bar = () => console.log('called')
> false || foo( bar() )
called
undefined
> true || foo( bar() )
true

Does this PR introduce a breaking change?

  • Yes
  • No

Rely on JS short circuit on OR operation to generate the uuid v4 only if the factory key was not provided
@kamilmysliwiec
Copy link
Member

Nice! Thank you

@kamilmysliwiec kamilmysliwiec merged commit 6f8b0e8 into nestjs:master Apr 5, 2022
@micalevisk micalevisk deleted the patch-1 branch April 5, 2022 11:09
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.

2 participants