Skip to content

WCProductTagModel to Room #14003

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

Merged
merged 13 commits into from
May 15, 2025
Merged

WCProductTagModel to Room #14003

merged 13 commits into from
May 15, 2025

Conversation

wzieba
Copy link
Contributor

@wzieba wzieba commented May 2, 2025

Closes: AINFRA-127

Description

This PR migrates WCProductTagModel to Room.

Steps to reproduce

Testing information

Smoke test any feature that uses WCProductTagModel.

The tags are under + ADD MORE DETAILS button on the details of the product:

image

Images/gif

Screenshot 2025-05-05 at 13 29 05
  • 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.

wzieba added 5 commits May 2, 2025 12:16
Introduce ProductTagsDao, replace SELECT queries with the new Dao.
`:libs:fluxc-plugin:testDebugUnitTest` passes
@dangermattic
Copy link
Collaborator

dangermattic commented May 2, 2025

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 22.4. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 2, 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
Commit18ffeb6
Direct Downloadwoocommerce-wear-prototype-build-pr14003-18ffeb6.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 2, 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
Commit18ffeb6
Direct Downloadwoocommerce-prototype-build-pr14003-18ffeb6.apk

@codecov-commenter
Copy link

codecov-commenter commented May 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 57 lines in your changes missing coverage. Please review.

Project coverage is 38.44%. Comparing base (2f8a1e7) to head (18ffeb6).
Report is 6 commits behind head on trunk.

Files with missing lines Patch % Lines
...rg/wordpress/android/fluxc/store/WCProductStore.kt 0.00% 24 Missing ⚠️
...roid/ui/products/details/ProductDetailViewModel.kt 0.00% 11 Missing ⚠️
...wordpress/android/fluxc/model/WCProductTagModel.kt 0.00% 7 Missing ⚠️
...network/rest/wpcom/wc/product/ProductRestClient.kt 0.00% 7 Missing ⚠️
...rdpress/android/fluxc/persistence/WellSqlConfig.kt 0.00% 4 Missing ⚠️
.../android/ui/products/tags/ProductTagsRepository.kt 0.00% 2 Missing ⚠️
...kotlin/com/woocommerce/android/model/ProductTag.kt 0.00% 1 Missing ⚠️
...ss/android/fluxc/persistence/dao/ProductTagsDao.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14003      +/-   ##
============================================
+ Coverage     38.43%   38.44%   +0.01%     
  Complexity     9606     9606              
============================================
  Files          2126     2127       +1     
  Lines        116952   116916      -36     
  Branches      15027    15028       +1     
============================================
+ Hits          44952    44953       +1     
+ Misses        67882    67846      -36     
+ Partials       4118     4117       -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wzieba wzieba added status: blocked Blocked from progressing somehow, waiting for another piece of work to be done. type: technical debt Represents or solves tech debt of the project. labels May 5, 2025
@wzieba wzieba requested a review from Copilot May 5, 2025 11:36
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 migrates the WCProductTagModel from a legacy WellSql-based implementation to a modern Room-based architecture. Key changes include converting WCProductTagModel into a Room @entity data class, adding a ProductTagsDao with associated database updates and tests, and updating repository and store methods to use suspend functions.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/fluxc-plugin/src/testFixtures/kotlin/org/wordpress/android/fluxc/wc/product/ProductTestUtils.kt Updated test utility to use the WCProductTagModel constructor.
libs/fluxc-plugin/src/test/java/org/wordpress/android/fluxc/leaderboards/* Updated tests to include productTagsDao where needed.
libs/fluxc-plugin/src/test/java/org/wordpress/android/fluxc/persistence/dao/ProductTagsDaoTest.kt Added new tests for the ProductTagsDao.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt Refactored product tag methods to use DAO methods with suspend functions.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt Updated the database version and added the productTagsDao.
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/model/WCProductTagModel.kt Converted to a data class with Room annotations.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/tags/ProductTagsRepository.kt Adjusted repository methods to suspend functions.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailViewModel.kt Updated to use suspend functions; however, a runBlocking call was introduced.

@@ -2404,7 +2405,7 @@ class ProductDetailViewModel @Inject constructor(
fun onProductTagAdded(tagName: String) {
// verify if the entered tagName exists for the site
// It so, the tag should be added to the product directly
productTagsRepository.getProductTagByName(tagName)?.let {
runBlocking { productTagsRepository.getProductTagByName(tagName) }?.let {
Copy link
Preview

Copilot AI May 5, 2025

Choose a reason for hiding this comment

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

Using runBlocking in a ViewModel's UI method may block the main thread. Consider launching a coroutine within the ViewModel's scope instead of using runBlocking.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In previous scenarios and other migrations, I leaned over persisting this behavior (even if it meant blocking a thread), as I didn't want to introduce yet another variable to the migration process. But in this case, I think it's indeed quite safe. I tested it and it looks fine. Suggestion addressed in: befc13c

wzieba added 2 commits May 5, 2025 13:46
In this case, it seems completely safe to use `viewModelScope` right away
@wzieba wzieba marked this pull request as ready for review May 5, 2025 15:33
@wzieba wzieba requested a review from ParaskP7 May 5, 2025 15:33
…erce/woocommerce-android into migrate_product_tag_to_room
Copy link
Contributor

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

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

👋 @wzieba !

I have reviewed and tested this PR as per the instructions, everything works as expected (ish), one more migration (almost) done! ✅ 💪 🚀


Warning (⚠️): This ish above is just because of the fact that during this migration I am not seeing the WCProductTagModel table being dropped from the wp-fluxc database (just like it was done here as an example).

WellSqlConfig.kt

open class WellSqlConfig : DefaultWellConfig {
    ...
    override fun getDbVersion(): Int {
        return 211
    }

    override fun onUpgrade(...) {
                ...
                210 -> migrateAddOn(ADDON_WOOCOMMERCE, version) {
                    db.execSQL("DROP TABLE IF EXISTS WCProductTagModel")
                }
                ...
    }
    ...
}

PS: The 211 db version takes into account that a similar 210 migration will happen as part of #13996 (see ⚠️ on review).


I have left one warning (⚠️), one suggestions (💡) and some minor (🔍) comments for you to consider. I am NOT going to approve this PR for now, just because of this one warning, instead I am hitting request changes.


FYI: As soon as these #14027 and #13966 PRs gets reviewed, tested and merged, my plan is to proceed with these changes myself, unless of course you've already returned from AFK by then. 😊 🤷

Base automatically changed from migrate_product_category_to_room to trunk May 15, 2025 06:10
@wzieba wzieba added this to the 22.4 milestone May 15, 2025
@wzieba wzieba removed the status: blocked Blocked from progressing somehow, waiting for another piece of work to be done. label May 15, 2025
@wzieba wzieba changed the title [WIP] WCProductTagModel to Room WCProductTagModel to Room May 15, 2025
@wzieba wzieba requested a review from ParaskP7 May 15, 2025 07:42
Copy link
Contributor

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

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

👋 @wzieba , I did another review on this after those new commits you pushed today and everything LGTM, I also tested the migration/app once more and (obviously) it works as expected. Thanks a lot! 🙇 ❤️ 🚀

It is a ✅ from my side, so I am approving this. I am not sure if you also want someone from the product team to do some more testing on this change before merging. I'll leave that up to you. 👍

@wzieba wzieba merged commit 769b416 into trunk May 15, 2025
19 of 20 checks passed
@wzieba wzieba deleted the migrate_product_tag_to_room branch May 15, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: technical debt Represents or solves tech debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants