Skip to content

Conversation

@hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Oct 10, 2024

Closes: #12664

Description

This PR updates the logic of saving the AI generated product as draft to make the preparation requests in parallel, this should speed up the process, and it's how iOS is handling it.

To make the upload request also in parallel, I moved it to the usecase SaveAiGeneratedProduct, which required some changes to the ViewModel too.

From my tests, with this change, the saving (including image upload) was reduced from 12 seconds to 7 seconds in my test website.

Steps to reproduce

  1. Open the app.
  2. Navigate to the Products tab.
  3. Start product creation and select AI creation.
  4. Complete the flow.

Testing information

  • Test creation when having an image.
  • Test creation without image.

The tests that have been performed

^

Images/gif

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. feature: product details Related to adding or editing products, includes product settings. labels Oct 10, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 10, 2024

1 Warning
⚠️ This PR is assigned to the milestone 20.8. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 10, 2024

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitefb4286
Direct Downloadwoocommerce-wear-prototype-build-pr12770-efb4286.apk

@hichamboushaba hichamboushaba added this to the 20.8 milestone Oct 10, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 10, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitefb4286
Direct Downloadwoocommerce-prototype-build-pr12770-efb4286.apk

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 24.61538% with 49 lines in your changes missing coverage. Please review.

Project coverage is 40.84%. Comparing base (5a9dbdd) to head (efb4286).
Report is 115 commits behind head on trunk.

Files with missing lines Patch % Lines
...e/android/ui/products/ai/SaveAiGeneratedProduct.kt 4.00% 48 Missing ⚠️
...i/products/ai/preview/AiProductPreviewViewModel.kt 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #12770      +/-   ##
============================================
- Coverage     40.86%   40.84%   -0.02%     
+ Complexity     5757     5752       -5     
============================================
  Files          1236     1236              
  Lines         69722    69738      +16     
  Branches       9668     9673       +5     
============================================
- Hits          28490    28486       -4     
- Misses        38604    38624      +20     
  Partials       2628     2628              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hichamboushaba hichamboushaba requested review from JorgeMucientes and irfano and removed request for JorgeMucientes October 11, 2024 14:08
@hichamboushaba hichamboushaba marked this pull request as ready for review October 11, 2024 14:08
@JorgeMucientes JorgeMucientes self-assigned this Oct 16, 2024
Copy link
Contributor

@JorgeMucientes JorgeMucientes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @hichamboushaba code changes look great and everything is still working as expected. I didn't notice such a big improvement in the the time taken to save the product as you experienced on your site, but still I could see like 2-3 secs improvement on my tests. In any case the changes make sense and code is cleaner and more optimized now.

}

is AiProductSaveResult.Failure -> {
// Keep track of the uploaded image to avoid re-uploading it on retry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 💯

@JorgeMucientes JorgeMucientes merged commit 06fce27 into trunk Oct 16, 2024
@JorgeMucientes JorgeMucientes deleted the issue/12664-ai-product-parallel-requests branch October 16, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: product details Related to adding or editing products, includes product settings. type: enhancement A request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Product AI] Make API requests in parallel when saving the product as draft

6 participants