Core Data: Move write operations in CardPresentPaymentStore to the background #14131
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.
Closes: #14130
Description
This PR continues the work to improve our Core Data usage in the app by moving write operations
CardPresentPaymentStore
to the background.For more context: we want to handle all write operations in the background context, and save the changes to its parent - the persistent container. The view context would get merges directly from the persistent container, and should be used only for reading data. Writing to the view context causes performances issues, and changes made are not merged back to the background context causing data discrepancy.
The changes in this PR include:
upsertStoredAccountInBackground
anddeleteStaleAccount
implementation to be handled in the background.upsertStoredAccountInBackground
to always delete existing accounts and insert new ones. Previously, we attempted to fetch an existing account and update it after deleting existing accounts, which is redundant.upsertCharge
anddeleteCharge
to be handled in the background.Steps to reproduce
Testing account fetching:
⚠️ Write operations for PaymentGatewayAccount should only be done on a background context
or⚠️ Saving data should only be done on a background context
.Testing charge fetching:
Testing information
Tested on simulator iPhone 16 Pro iOS 18.1 and confirmed that payment account loading and refund both work as expected.
Screenshots
N/A
RELEASE-NOTES.txt
if necessary.TODO: @itsmeichigo to update the release notes before merging
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: