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): correctly processing Delta Sync query response in RN #8196

Merged
merged 2 commits into from
May 3, 2021

Conversation

iartemiev
Copy link
Member

Description of changes

Fixes the way a Delta Sync query response is processed in React Native.

Current behavior

The batchSave method in the AsyncStorageDatabase class separates incoming records from a delta query response into saves and deletes. It then sequentially performs a multiRemove of all the delete operations, followed by a multiSet of the save ops.

So in the event that we have a create/update operation as well as a delete op for a record with the same id within the timespan of the delta sync record TTL, the create/update will win out locally, regardless of its _version or _lastChangedAt value.

Change introduced

The change in this PR adds a step that iterates through the records from the delta sync response in the order they're received and creates a Map with a key of id from the records. The map is then iterated over before splitting out the records into saves and deletes. This way, only the latest version of the record for a given model id ends up getting persisted to the local store.

Issue #, if available

#8158

Description of how you validated changes

  • Manual validation in sample app
  • Added unit test
  • e2e test

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
    N/A Relevant documentation is changed or added (and PR referenced)

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

@iartemiev iartemiev added the DataStore Related to DataStore category label Apr 28, 2021
@iartemiev iartemiev changed the title fix(@aws-amplify/datastore): processing Delta Sync query response in RN fix(@aws-amplify/datastore): correctly processing Delta Sync query response in RN Apr 28, 2021
@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2021

Codecov Report

Merging #8196 (978eb31) into main (d16a8fb) will increase coverage by 0.84%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8196      +/-   ##
==========================================
+ Coverage   76.91%   77.76%   +0.84%     
==========================================
  Files         233      233              
  Lines       15228    16282    +1054     
  Branches     2979     3474     +495     
==========================================
+ Hits        11713    12661     +948     
- Misses       3288     3514     +226     
+ Partials      227      107     -120     
Impacted Files Coverage Δ
...astore/src/storage/adapter/AsyncStorageDatabase.ts 85.80% <ø> (+30.38%) ⬆️
packages/datastore/src/sync/merger.ts 91.30% <100.00%> (+8.95%) ⬆️
...es/Providers/AbstractConvertPredictionsProvider.ts 78.57% <0.00%> (-8.93%) ⬇️
...s/Providers/AbstractIdentifyPredictionsProvider.ts 78.57% <0.00%> (-8.93%) ⬇️
...ckages/amazon-cognito-identity-js/src/UserAgent.js 91.66% <0.00%> (-8.34%) ⬇️
.../Providers/AbstractInterpretPredictionsProvider.ts 83.33% <0.00%> (-7.58%) ⬇️
...tions/src/Providers/AmazonAIPredictionsProvider.ts 82.75% <0.00%> (-5.71%) ⬇️
packages/datastore/src/types.ts 75.96% <0.00%> (-5.12%) ⬇️
packages/analytics/src/trackers/SessionTracker.ts 71.60% <0.00%> (-4.40%) ⬇️
packages/aws-amplify-react/src/XR/IconButton.tsx 46.42% <0.00%> (-3.58%) ⬇️
... and 123 more

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 d16a8fb...978eb31. Read the comment docs.

@iartemiev iartemiev force-pushed the ds-async-storage-delta-sync branch from e606a6a to 48b2d91 Compare April 28, 2021 20:35
@iartemiev iartemiev force-pushed the ds-async-storage-delta-sync branch from 48b2d91 to 978eb31 Compare May 3, 2021 18:42
@iartemiev iartemiev force-pushed the ds-async-storage-delta-sync branch from 978eb31 to 11f4fe2 Compare May 3, 2021 18:54
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.

LGTM 👍 🎉

@github-actions
Copy link

github-actions bot commented May 4, 2022

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 May 4, 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