Defer saving to persistence store until sync is completed #78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
SynchronizationManager
, a call tosave()
inupdate(with:)
entailed that non-optional relationships that were synced across multiple pages were not resolved when CoreData validated the relationship after processing each page, which resulted in an unrecoverable error. The solution proposed in this PR is to defer callingsave()
until the sync has no more pages to process. Thus, the relationship validation is performed only after the last page has been processed.To ensure that the deferral of calling
save()
does not negatively affect other use cases, asserts have been added to most complex sync tests that ensure that the synced records have been written to storage (hasChanges == false
).