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

Code cleanup #110

Merged
merged 7 commits into from
Sep 23, 2021
Merged

Code cleanup #110

merged 7 commits into from
Sep 23, 2021

Conversation

darkgl0w
Copy link
Member

@darkgl0w darkgl0w commented Sep 23, 2021

Hello,

I did a little refresh:

  • on test files: explicit test naming and an addition of 2 more test cases
  • on plugin code: initialization of fastify.pg and req.pg with Object.create(null) instead of {}, little if.. statements reorganization to fail fast and improve code readability

And I updated this package dependencies too.

Checklist

@coveralls
Copy link

coveralls commented Sep 23, 2021

Pull Request Test Coverage Report for Build 1265207839

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1118719299: 0.0%
Covered Lines: 102
Relevant Lines: 102

💛 - Coveralls

@coveralls
Copy link

coveralls commented Sep 23, 2021

Pull Request Test Coverage Report for Build 1265335457

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1118719299: 0.0%
Covered Lines: 102
Relevant Lines: 102

💛 - Coveralls

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Good work, this was much needed! I've left a small note.

@@ -102,19 +102,21 @@ function fastifyPostgres (fastify, options, next) {
if (db[name]) {
return next(new Error(`fastify-postgres '${name}' is a reserved keyword`))
} else if (!fastify.pg) {
fastify.decorate('pg', {})
fastify.decorate('pg', Object.create(null))
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, what is the advantage of this approach?

Copy link
Member Author

Choose a reason for hiding this comment

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

When we use Object.create(null) we initialize a really empty object that inherit nothing.
Initializing the decorator with {} instead is equivalent to Object.create(Object.prototype) and we have an object that inherit the __proto__ property.
But in fact it can be considered to be just a minor optimization.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Eomm Eomm merged commit cedc35e into fastify:master Sep 23, 2021
@darkgl0w darkgl0w deleted the code-cleanup branch September 25, 2021 07:43
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.

5 participants