Skip to content
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: Optimize storage usage in ProductReviewStore #14134

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Oct 16, 2024

Closes: #14133

Description

This PR updates ProductReviewStore for better usage of storage following the recent updates of CoreDataManager. Specifically:

  • Moved write operations to the background for resetStoredProductReviews, deleteStoredProductReview, and moderateReview.
  • Updated upsertStoredProductReviewsInBackground to use the new method performAndSave.
  • Updated RetrieveProductReviewFromNoteUseCase to receive the storage manager instead of storage.

Steps to reproduce

  • Log in to a store with existing products and reviews.
  • Navigate to the Menu tab > select Reviews. Confirm that the review list is loaded successfully.
  • Change the status for a review and confirm that it works correctly.
  • Switch to another store, confirm that there's no warning in Xcode console saying "Write operations for ProductReview should only be done on a background context".
  • Build the app to a physical device then add a review to a product on your test store on the web.
  • When the notification for the review comes in your device, tap it and confirm that the review details are loaded successfully.

Testing information

Tested on device iPhone 16 Pro iOS 18.0.1 and confirmed that loading/moderating/opening review notifications work as expected.

Screenshots

N/A


  • I have considered if this change warrants user-facing release notes and have added them to 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:

  • 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 all devices (phone/tablet) and no regressions are added.

@itsmeichigo itsmeichigo added type: task An internally driven task. feature: review list Related to the reviews list. feature: review details Related to review details. labels Oct 16, 2024
@itsmeichigo itsmeichigo added this to the 20.8 milestone Oct 16, 2024
@wpmobilebot
Copy link
Collaborator

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

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14134-cdf4f53
Version20.7
Bundle IDcom.automattic.alpha.woocommerce
Commitcdf4f53
App Center BuildWooCommerce - Prototype Builds #11157
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@itsmeichigo itsmeichigo modified the milestones: 20.8, 20.9 Oct 18, 2024
@hafizrahman hafizrahman self-assigned this Oct 18, 2024
@hafizrahman
Copy link
Contributor

Testing note:

Tested in iPhone 15 Simulator with iOS 17.5

✅ Menu tab > Reviews shows reviews correctly
✅ Changing review status works
✅ No Xcode console warning when switching to another store

Tested in iPhone 14 Pro with iOS 17.4.1

✅ Notification appears when a review is added on the web
✅ Tapping notification opens to the review details correctly

Copy link
Contributor

@hafizrahman hafizrahman left a comment

Choose a reason for hiding this comment

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

code lgtm, just added a non-blocking comment.

func deleteStoredProductReview(siteID: Int64, reviewID: Int64, onCompletion: @escaping () -> Void) {
storageManager.performAndSave({ storage in
guard let productReview = storage.loadProductReview(siteID: siteID, reviewID: reviewID) else {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated to this PR but while reading the code, I wonder if it's worth adding a log here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: review details Related to review details. feature: review list Related to the reviews list. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize storage usage in ProductReviewStore
3 participants