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: optimize getFirst() and dependent methods #249

Merged
merged 2 commits into from
Jul 18, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Jul 15, 2022

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR optimizes getFirst() by defaulting to only query one document. It does this by setting pageSize=1.

The following methods also benefit from this optimization since they use getFirst() within their implementation:

  • getByID()
  • getByUID()
  • getSingle()
  • resolvePreviewURL()

Exceptions to this optimization:

  • If a page param is provided, pageSize is not set. pageSize affects the behavior of page, so we cannot automatically set pageSize to 1.
  • If a pageSize param is provided, it takes priority.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🐥

@github-actions
Copy link

github-actions bot commented Jul 15, 2022

size-limit report 📦

Path Size
dist/index.js 4.12 KB (+0.58% 🔺)
dist/index.cjs 7.02 KB (+0.33% 🔺)

@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2022

Codecov Report

Merging #249 (de04971) into master (62fdae1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #249   +/-   ##
=======================================
  Coverage   99.46%   99.47%           
=======================================
  Files          23       23           
  Lines         377      379    +2     
  Branches       76       78    +2     
=======================================
+ Hits          375      377    +2     
  Partials        2        2           
Impacted Files Coverage Δ
src/client.ts 99.11% <100.00%> (+<0.01%) ⬆️

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 62fdae1...de04971. Read the comment docs.

@angeloashmore angeloashmore requested a review from lihbr July 15, 2022 21:45
Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

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

LGTM 👏

@angeloashmore angeloashmore merged commit ed06cec into master Jul 18, 2022
@angeloashmore angeloashmore deleted the aa/optimize-get-first branch July 18, 2022 22:08
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.

None yet

3 participants