[Crash] Fix crash when searching products in order product selector #14095
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: #14085
Description
This fixes a crash caused by fetching products from storage while updating them in the same context on a background thread. This happened while performing a product search in the order form product selector (while adding products to an order).
This also includes a small improvement to the local search, to return results with partial matches to the search term (similar to the remote search method) instead of only exact matches.
How
sharedDerivedStorage
(which isstorageManager.writerDerivedStorage
, meant for writing to storage and used for background updates) we now usestorageManager.viewStorage
to fetch the products.CONTAINS
instead ofLIKE
(to return partial matches).Steps to reproduce
Note: I was only able to get the app to crash in the simulator. I couldn't reproduce this crash on a device, but as the simulator crash indicates this action is not thread safe.
_PFAssertSafeMultiThreadedAccess_impl
.Testing information
Test with the same steps as above in this branch and confirm it doesn't crash.
Additional testing:
Card
when you have a product calledGift Card
in the first page of results) and confirm the match is loaded from storage.Screenshots
Screencast demonstrates the following search scenarios:
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-10-02.at.17.01.49.mp4
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: