Skip to content

[1/2] WCProductVariationModel to Room: working app #13972

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

Open
wants to merge 21 commits into
base: feature/product_variation_to_room
Choose a base branch
from

Conversation

wzieba
Copy link
Contributor

@wzieba wzieba commented Apr 24, 2025

Description

This PR migrates WCProductVariationModel from WellSql to Room. It's similar to #13935, but this time the migration has smaller scope, as WCProductVariationModel is not used in that many places.

  • The real diff of this PR is +343 / -396, excluding JSON schema file
  • Most changes are related to the fact of changing WCProductVariationModel to a data class with immutable members

Testing information

Please test using #13982

Images/gif

Screenshot 2025-04-30 at 13 32 21
  • 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.

@dangermattic
Copy link
Collaborator

dangermattic commented Apr 24, 2025

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class ProductVariationsDao is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 24, 2025

📲 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
Commit886bff1
Direct Downloadwoocommerce-wear-prototype-build-pr13972-886bff1.apk

Base automatically changed from migrate_tests_to_products_room to products_to_room April 25, 2025 08:16
Base automatically changed from products_to_room to trunk April 25, 2025 09:03
wzieba added 2 commits April 25, 2025 15:19
…e to app model mapper, make query methods suspendable
To reduce chance of similar mistake in the future, I propose using `LocalId/RemoteId` wrappers.
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 25, 2025

📲 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
Commit886bff1
Direct Downloadwoocommerce-prototype-build-pr13972-886bff1.apk

@wzieba wzieba requested a review from Copilot April 28, 2025 14:05
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the WCProductVariationModel implementation to use Room for local data persistence and updates related DAO and store methods. Key changes include:

  • Replacing legacy WellSql operations with Room DAO methods and converting model instantiations from mutable apply blocks to immutable copy constructors.
  • Updating several functions to suspend functions and incrementing the database version to accommodate the WCProductVariationModel entity.
  • Removing obsolete ProductSqlUtils variation methods and updating network mappers and repositories to align with the new model.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libs/fluxc-plugin/src/testFixtures/kotlin/org/wordpress/android/fluxc/wc/product/ProductTestUtils.kt Replaced legacy model instantiation with constructor parameters.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt Updated variation access methods to suspend functions, replacing legacy SQL utils with DAO calls.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/dao/ProductVariationsDao.kt Introduced a new Room DAO for product variations.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt Added WCProductVariationModel as an entity and incremented the database version.
Multiple network and repository files Updated model instantiation and copy patterns to ensure immutability and consistency.
Comments suppressed due to low confidence (2)

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt:79

  • Ensure that the migration from database version 39 to 40 is thoroughly tested, especially with regard to the new WCProductVariationModel schema and data integrity.
const val WC_DATABASE_VERSION = 40

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt:828

  • Confirm that all call sites for variation-related methods are updated to handle the new suspend signatures to prevent unintended blocking or concurrency issues.
suspend fun getVariationByRemoteId(

Comment on lines +153 to +163
fun attributesToJson(): String {
val jsonArray = JsonArray()
attributes.forEach { variantOption ->
JsonObject().apply {
addProperty("id", variantOption.id)
addProperty("name", variantOption.name)
addProperty("option", variantOption.option)
}.also { jsonArray.add(it) }
}
return jsonArray.toString()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this replaces addVariant method. I like it doesn't need gson object (we shouldn't use gson inside models, nor create instance of gson per model), but we also loose synchronization of fields with ProductVariantOption. I think it's acceptable, because I think it's unlikely this model will change.

https://github.com/woocommerce/woocommerce-android/pull/13972/files#diff-a2f8ea1eb59520371a927db507f69e8a3da9de51a52c6cb1665a1bb2b56cbe17L108-L115

}
@Entity(
tableName = "ProductVariationEntity",
primaryKeys = ["localSiteId", "remoteProductId", "remoteVariationId"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This primaryKeys introduces a new behavior of UNIQUE constraint, which wasn't present before, yet I think it's expected.

wzieba added 7 commits April 29, 2025 12:01
In case when `jacocoTestReport` task fails, our script was not moving test results to the correct directory, as it was exiting on error before collection.
…erage only on success tests

This will reduce chances of `testJalapenoDebugUnitTest` task being not up to date when running `jacocoTestReport`, which caused running unit tests again, without any reason.
To address issues like: Reason: Task ':jacocoTestReport' uses this output of task ':libs:apifaker:testDebugUnitTest' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
There are two reasons for this:
- with the current setup, we were opening "Copying test logs for test collector" if tests failed, because this was the last collapsed regular group (docs: https://buildkite.com/docs/pipelines/configure/managing-log-output#collapsing-output) and it was confusing: tests did fail, not copying test logs
- developers are much more interested in details of `Testing` step than (empty) details of "Copying test logs" so it makes sense to open former by default
@wzieba wzieba changed the title [WIP] WCProductVariationModel to Room: working app [1/2] WCProductVariationModel to Room: working app Apr 30, 2025
@wzieba wzieba changed the base branch from trunk to feature/product_variation_to_room April 30, 2025 11:50
wzieba added 2 commits April 30, 2025 19:45
…coco_fail

Fix Buildkite test collector support when tests execution fail
@wzieba wzieba requested a review from ParaskP7 April 30, 2025 18:00
@wzieba wzieba marked this pull request as ready for review April 30, 2025 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants