Update ProductsRemote
to load products with async/throws network methods to parse response in a background thread
#15781
+228
−211
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 WOOMOB-605
Just one reviewer is required.
Why
In most of the network calls except for the
enqueue<M: Mapper>(_ request: Request, mapper: M) async throws -> M.Output
version, the response is parsed by a mapper on the main thread. When the response size is large like in the support case in WOOMOB-607 with a large amount of product metadata, the UI could become unresponsive. This PR updates the remainingProductsRemote
functions that return a product list from the previous Combine/completion block basedenqueue
method to theenqueue<M: Mapper>(_ request: Request, mapper: M) async throws
method, so that the response parsing along with other network related tasks are performed in the background thread. There are already several use cases ofenqueue<M: Mapper>(_ request: Request, mapper: M) async throws
for a while that we can consider it stable.I'm prioritizing network calls for entities with a potentially large amount of data like from metadata (Product and Order) or some collection fields.
Description
Refactoring to
async/await
inProductsRemote
:ProductsRemoteProtocol
method signatures to replace completion handlers withasync throws
for methods likeloadProducts
,searchProducts
, andsearchProductsBySKU
. [1] [2]ProductsRemote
implementation to useasync throws
and removed completion handler logic. Simplified error handling and return values, such as returning an empty array directly for empty product IDs. [1] [2]Test case updates:
ProductsRemoteTests
to useasync/await
for methods likeloadProducts
,searchProducts
, andsearchProductsBySKU
. Removed completion-based test logic and added proper error handling forasync
tests. [1] [2]ProductStore updates:
ProductStore
to useasync/await
when interacting withProductsRemote
. This includes replacing completion handlers withTask
blocks and handling results in a streamlined manner. Store action completion blocks are called on the main thread, while await methods can be in a background thread. [1] [2]Mapper simplification:
ProductListMapper
with a genericListMapper<Product>
in several methods to simplify the mapping logic for product-related API responses. This mapper is no longer used and will be removed in a future PR. [1] [2]Steps to reproduce
Prerequisite: put a breakpoint in
ListMapper
decode calls in Xcode; the store should have a few products and at least one reviewProductStore.retrieveProducts
in a background thread. after the breakpoint, the corresponding products should be loaded correctly as beforeProductStore.searchProducts
in a background thread. after the breakpoint, the matching products should be loaded correctly as beforeProductStore.searchProducts
in a background thread. after the breakpoint, the matching products should be loaded correctly as beforeProductStore.requestMissingProducts
in a background thread. after the breakpoint, the matching products should be loaded correctly as beforeTesting information
I tested above use cases on an iOS 18.5 iPad device.
RELEASE-NOTES.txt
if necessary.