-
Notifications
You must be signed in to change notification settings - Fork 111
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
Core Data Stack updates #14013
Core Data Stack updates #14013
Conversation
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
This reverts commit 37c983f.
Version |
Moved the milestone to 20.8 to avoid causing any issue during the Woo DM. Other PRs will be based on top of this PR and merged gradually after this PR is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, Huong! 👏
The changes LGTM, and it works well on an iPhone simulator running iOS 17.4.
I left a few non-blocking suggestions and questions.
Thanks @selanthiraiyan for the reviews! I responded to your comments regarding the unit tests, let me know what you think. I'll merge the PR once I get another green light from you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates and comments, Huong! Let us merge this PR. 🚢
Closes: #14054
Also closes: #2370
Description
This PR adds a few improvements to the Core Data stack:
writerDerivedStorage
to be independent of the main context. Instead, the background context is now directly associated with the persistent container following Apple's recommendation. The main context now merges changes from the persistent container automatically.performBackgroundTask
- we want to avoid creating too many background context through this method.saveDerivedType
to only save the background context to the persistent container.writerDerivedStorage
andsaveDerivedType
as deprecated and added a helper methodperformAndSave
for performing write operations similarly to WP/JP's Core Data stack. Updates for the stores will be handled in future PRs.-enforce-core-data-write-in-background
has been added to enableassert
when writing is done on the main context.AppDelegate
to ensure that the Core Data stack is created before the stores manager. This is an attempt to eliminate confusing stack traces [peaMlT-Rx-p2#comment-2194]. The order of initialization should now be as follows: CrashLogging > CoreDataManager > DefaultStoresManager.date
anddateCreated
Swift properties optional to avoid crashes when transforming deleted product objects in Core Data.TODO: @itsmeichigo to update the release notes before merging.
Steps to reproduce
Smoke testing the app
-enforce-core-data-write-in-background
disabled, build and run the app in debug mode.Testing enforcing write in background
-enforce-core-data-write-in-background
enabled, build and run the app in debug mode.assert
causes a fatal error where a write operation is handled in the main context.Testing information
Tested on device iPad pro 4th gen iOS 17.6:
Tested on simulator iPhone 15 Pro iOS 17.4 and
-enforce-core-data-write-in-background
enabled and confirmed that write operations in the main context causes assertion failure.Screenshots
N/A
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: