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

fix(@aws-amplify/datastore): improve IDB query performance #7746

Merged
merged 6 commits into from
Feb 20, 2021

Conversation

iartemiev
Copy link
Member

@iartemiev iartemiev commented Feb 14, 2021

This PR fixes a bug where calling DataStore.query(Post) without a pagination object would use the cursor-based fetch from IndexedDB, as opposed to getAll(), which is optimized specifically for getting all the records. This was having a negative effect on the performance of DataStore.query when retrieving all the items for a given model.

The pagination object was getting initialized to {limit: undefined, page: undefined, sort: undefined} in the DataStore.processPagination private method, therefore pagination always had a truthy value in the conditional checks that determine which retrieval method to utilize. This gets fixed here.

Also:

  • Refactored IndexedDBAdapater.query to make it easier to test
  • Added test coverage for IndexedDBAdapter, which ensures the correct retrieval method is used for all of the different combinations of parameters passed to IndexedDBAdapter.query

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov
Copy link

codecov bot commented Feb 14, 2021

Codecov Report

Merging #7746 (e5df7b2) into main (aecdf3c) will increase coverage by 0.05%.
The diff coverage is 98.70%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7746      +/-   ##
==========================================
+ Coverage   74.07%   74.13%   +0.05%     
==========================================
  Files         214      215       +1     
  Lines       13410    13450      +40     
  Branches     2628     2641      +13     
==========================================
+ Hits         9934     9971      +37     
- Misses       3277     3280       +3     
  Partials      199      199              
Impacted Files Coverage Δ
.../datastore/src/storage/adapter/IndexedDBAdapter.ts 78.40% <97.50%> (+0.66%) ⬆️
packages/datastore/src/datastore/datastore.ts 78.42% <100.00%> (+0.34%) ⬆️
...tastore/src/storage/adapter/AsyncStorageAdapter.ts 78.04% <100.00%> (+0.83%) ⬆️
...ges/datastore/src/storage/adapter/InMemoryStore.ts 72.72% <0.00%> (ø)
packages/datastore/src/util.ts 80.40% <0.00%> (+0.50%) ⬆️

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 aecdf3c...e5df7b2. Read the comment docs.

@iartemiev iartemiev changed the title fix(@aws-amplify/datastore): improve query performance fix(@aws-amplify/datastore): improve IDB query performance Feb 14, 2021
@iartemiev iartemiev self-assigned this Feb 14, 2021
@iartemiev iartemiev added the DataStore Related to DataStore category label Feb 14, 2021
@iartemiev iartemiev force-pushed the ds-query-performance branch from 31df8ce to e36ee36 Compare February 15, 2021 01:55
Copy link
Contributor

@amhinson amhinson left a comment

Choose a reason for hiding this comment

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

Everything looks good to me. The refactor is much easier to follow. Although what do you think about doing the same thing for AsyncStorageAdapter for consistency's sake?

@iartemiev iartemiev force-pushed the ds-query-performance branch from e36ee36 to 1e4f0b2 Compare February 17, 2021 14:24
Copy link
Contributor

@manueliglesias manueliglesias left a comment

Choose a reason for hiding this comment

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

It looks great!

I left 2 comments but they are non-blocking, let me know your thoughts

@iartemiev iartemiev force-pushed the ds-query-performance branch from 1e4f0b2 to e44cdff Compare February 19, 2021 15:12
@iartemiev
Copy link
Member Author

Everything looks good to me. The refactor is much easier to follow. Although what do you think about doing the same thing for AsyncStorageAdapter for consistency's sake?

@amhinson Agreed! I've refactored AsyncStorageAdapater.query to follow the same pattern and have added unit tests

@iartemiev iartemiev force-pushed the ds-query-performance branch 2 times, most recently from 87bca91 to 5fb1d56 Compare February 19, 2021 15:35
@iartemiev
Copy link
Member Author

@amhinson @manueliglesias - thanks for the thorough reviews and good suggestions, guys. I've updated the PR

Copy link
Contributor

@amhinson amhinson left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@iartemiev iartemiev force-pushed the ds-query-performance branch from 3b629d4 to e5df7b2 Compare February 20, 2021 16:00
@iartemiev iartemiev merged commit 5b87ad4 into aws-amplify:main Feb 20, 2021
@iartemiev iartemiev deleted the ds-query-performance branch February 20, 2021 16:11
dgonsan pushed a commit to dgonsan/amplify-js that referenced this pull request Mar 18, 2021
@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataStore Related to DataStore category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants