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(datastore): sync pending mutation events with latest synced metadata #3377

Merged
merged 8 commits into from
Jan 2, 2024

Conversation

5d
Copy link
Contributor

@5d 5d commented Nov 23, 2023

Issue #

#1308

Description

  • This patch aligns with the existing amplify-android logic:
    • Apply metadata (version) from incoming mutation events when there is an pending mutation.
    • When syncing with AppSync, retrieve the latest synchronized metadata (version) and submit it along with the pending mutation event.

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

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

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (459aaed) 68.16% compared to head (29cea64) 68.12%.
Report is 3 commits behind head on main.

Files Patch % Lines
...eAndLocalSave/ReconcileAndLocalSaveOperation.swift 88.52% 7 Missing ⚠️
...ngMutationQueue/SyncMutationToCloudOperation.swift 60.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3377      +/-   ##
==========================================
- Coverage   68.16%   68.12%   -0.05%     
==========================================
  Files        1079     1078       -1     
  Lines       36033    35987      -46     
==========================================
- Hits        24563    24517      -46     
  Misses      11470    11470              
Flag Coverage Δ
API_plugin_unit_test 67.07% <ø> (ø)
AWSPluginsCore 64.45% <ø> (ø)
Amplify 47.83% <ø> (ø)
Analytics_plugin_unit_test 81.16% <ø> (ø)
Auth_plugin_unit_test 79.37% <ø> (-0.13%) ⬇️
CoreMLPredictions_plugin_unit_test 59.44% <ø> (ø)
DataStore_plugin_unit_test 80.84% <88.31%> (+0.06%) ⬆️
Geo_plugin_unit_test 70.75% <ø> (ø)
Logging_plugin_unit_test 63.09% <ø> (ø)
Predictions_plugin_unit_test 37.29% <ø> (ø)
PushNotifications_plugin_unit_test 87.03% <ø> (ø)
Storage_plugin_unit_test 78.10% <ø> (ø)
unit_tests 68.12% <88.31%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@5d 5d marked this pull request as ready for review November 27, 2023 21:56
@5d 5d requested a review from a team as a code owner November 27, 2023 21:56
Copy link
Contributor

@lawmicha lawmicha left a comment

Choose a reason for hiding this comment

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

Some follow up questions, first and formost would be: Should MutationEvent's version property be deprecated?

Exploring if we removed version from MutationEvent:

  • OutgoingMutationQueue processes existing pending mutations by reconciling the version from the incoming mutation response through MutationEvent.reconcilePendingMutationEventsVersion. Is this still needed if we always get the latest sync metadata from storage?
  • ReconcileAndLocalSaveOperation will call notify(savedModel:mutationType) and the hub payload is a MutationEvent. if the answer to the first question is that version is deprecated, then this will impact customers listening to hub events with MutationEvent payloads.
  • Similar question to above, MutationEvent is also the event for DataStore.observe API. Asking the deprecated question in another way: Are other platform's observe API returning data that contains the version as well?
  • Some other areas of interest is AWSMutationDatabaseAdapter

@5d
Copy link
Contributor Author

5d commented Nov 28, 2023

Some follow up questions, first and formost would be: Should MutationEvent's version property be deprecated?

Exploring if we removed version from MutationEvent:

  • OutgoingMutationQueue processes existing pending mutations by reconciling the version from the incoming mutation response through MutationEvent.reconcilePendingMutationEventsVersion. Is this still needed if we always get the latest sync metadata from storage?
  • ReconcileAndLocalSaveOperation will call notify(savedModel:mutationType) and the hub payload is a MutationEvent. if the answer to the first question is that version is deprecated, then this will impact customers listening to hub events with MutationEvent payloads.
  • Similar question to above, MutationEvent is also the event for DataStore.observe API. Asking the deprecated question in another way: Are other platform's observe API returning data that contains the version as well?
  • Some other areas of interest is AWSMutationDatabaseAdapter

I think for now, the safest way to do is mark it as deprecated field. If we remove the version field, shouldn't it be a major version change? For those customer who still using the mutation event version, the version will have the same value and meaning as before.

completion: completion)
let operation = await SyncMutationToCloudOperation(
mutationEvent: mutationEvent,
getLatestSyncMetadata: { nil },
Copy link
Contributor

Choose a reason for hiding this comment

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

We can test passing in a closure that returns non-nil as well and assert the API call is made with the version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update the test!

@5d 5d merged commit a0ee257 into main Jan 2, 2024
76 checks passed
@5d 5d deleted the 5d/fix-issue-1308 branch January 2, 2024 18:47
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.

3 participants