-
Notifications
You must be signed in to change notification settings - Fork 133
WCOrderSummary
to Room
#14315
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
base: trunk
Are you sure you want to change the base?
WCOrderSummary
to Room
#14315
Conversation
…ansaction for a possible small performance gain The need for "chunk" is an implementation constraint from SQL - it shouldn't leak to consumer of dao. Therefore this change name from "how" to simple "what".
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
It doesn't need it. Make `dateModified` nullable, as this is more correct interpretation of "no value" state than an empty string.
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #14315 +/- ##
=========================================
Coverage 37.69% 37.69%
+ Complexity 9054 9053 -1
=========================================
Files 1979 1980 +1
Lines 110994 110984 -10
Branches 14602 14602
=========================================
- Hits 41837 41836 -1
+ Misses 65336 65326 -10
- Partials 3821 3822 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 WCOrderSummary
data flow from WellSql into Room.
- Introduces a new
OrderSummaryDao
, Room entity (WCOrderSummaryModel
), and database migration (version bump to 54). - Refactors stores and clients (
WCOrderStore
,OrderUpdateStore
,OrderRestClient
, etc.) to use the new DAO instead ofOrderSqlUtils
. - Removes WellSql-based
OrderSqlUtils
methods and updates tests to target the new DAO.
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt | Bumped WellSql DB version and dropped old table. |
libs/fluxc-plugin/src/main/kotlin/.../persistence/dao/OrderSummaryDao.kt | New DAO with chunked queries and upsert methods. |
libs/fluxc-plugin/src/main/kotlin/.../model/WCOrderSummaryModel.kt | Converted model from WellSql annotations to Room. |
libs/fluxc-plugin/src/main/kotlin/.../WCAndroidDatabase.kt | Added WCOrderSummaryModel and DAO to Room DB. |
libs/fluxc-plugin/src/main/kotlin/.../store/WCOrderStore.kt | Updated store to call DAO instead of WellSql. |
libs/fluxc-plugin/src/main/kotlin/.../store/OrderUpdateStore.kt | Swapped OrderSqlUtils for DAO calls. |
libs/fluxc-plugin/src/test/java/.../persistence/dao/OrderSummaryDaoTest.kt | New tests covering basic DAO operations. |
WooCommerce/src/main/kotlin/.../OrderListItemDataSource.kt | Adapted UI data source to fetch via DAO. |
Comments suppressed due to low confidence (1)
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/dao/OrderSummaryDao.kt:24
- The chunking logic splits IDs into subsets of
CHUNK_SIZE
—it would be prudent to add a test case that verifiesgetOrderSummaries
handles lists larger thanCHUNK_SIZE
correctly.
return remoteOrderIds.chunked(CHUNK_SIZE)
) { | ||
@Ignore var dateModified: String? = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dateModified
field is marked with @Ignore
and won't be persisted, so its value is always null when fetching. You likely need to include it in the entity (remove @Ignore
and add it to the primary constructor) so that Room stores and retrieves the modified date correctly.
) { | |
@Ignore var dateModified: String? = null | |
} | |
val dateModified: String? = null // ISO 8601-formatted date in UTC, e.g. 1955-11-05T14:15:00Z | |
) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really - the previous WellSql implementation didn't had this field in db table as well:
Lines 877 to 882 in c68a743
db.execSQL( | |
"CREATE TABLE WCOrderSummaryModel (LOCAL_SITE_ID INTEGER,REMOTE_ORDER_ID INTEGER," + | |
"DATE_CREATED TEXT NOT NULL,_id INTEGER PRIMARY KEY AUTOINCREMENT," + | |
"FOREIGN KEY(LOCAL_SITE_ID) REFERENCES SiteModel(_id) ON DELETE CASCADE," + | |
"UNIQUE (REMOTE_ORDER_ID, LOCAL_SITE_ID) ON CONFLICT REPLACE)" | |
) |
so I guess it's intentional
summaries.filter { cachedOrders.containsKey(it.orderId) } | ||
} else { | ||
summaries | ||
val orderSummaries = runBlocking { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using runBlocking
in a UI data source can block the main thread and cause jank. Consider making this method suspendable or launching a coroutine in an appropriate scope instead of using runBlocking
.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well known comment. As always - it's intentional, as these migrations are not meant to resolve threading issues (sometimes they do when I'm sure there are no side effects)
There was a problem hiding this 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 (almost), everything works as expected, good job! 🌟 x 🌟 ^ 🌟
I have left one question (❓), one suggestions (💡) and one minor (🔍) comment for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.
EXTRAS
- Copilot wrote this and it made me 🤔 a bit:
The chunking logic splits IDs into subsets of CHUNK_SIZE—it would be prudent to add a test case that verifies getOrderSummaries handles lists larger than CHUNK_SIZE correctly.
- On this second step of testing information
2. Open the site on web, go to Tools > Smooth generator
, I could proceed as I was getting thiscritical error
below:

Any ideas, did that happen to you too? 🤔
FYI: I tried that 3 times already, 3 different sites... 🤷
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/model/WCOrderSummaryModel.kt
Show resolved
Hide resolved
"UNIQUE (REMOTE_ORDER_ID, LOCAL_SITE_ID) ON CONFLICT REPLACE" | ||
@Entity( | ||
tableName = "OrderSummaryEntity", | ||
primaryKeys = ["siteId", "orderId"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info (ℹ️): Just an FYI that after I migrated I noticed that, when navigating to the Orders
screen, the list of orders was empty and wouldn't auto-refresh. I then had to manually trigger pull-to-refresh to get the orders to show up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please confirm that it doesn't happen on trunk
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @wzieba , how do you suggest I confirm that this doesn't happen on trunk
? 🤔
FYI: To my understanding, I should uninstall/install the app to get a similar behavior, an empty WCOrderSummaryModel
table, correct? And, as far as I remember, whenever I uninstall/install the app from scratch, when navigating to the Orders
screen, the list of orders gets auto-populated for me, no need for a manual pull-to-refresh from my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I understand now. I wonder, we can either:
- leave it as it is (one time pull-to-refresh shouldn't be bothering)
- move the data from WellSql to Room database before removing the table (maybe worth experimenting with a solution for this as we'll have to do it anyway for
SiteModel
) - request summaries fetch if database has orders, but not summaries (it'll be one-time case, only after initial run after this migration)
I'll check how time-consuming would be the second point .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reply @wzieba ! 🙏
leave it as it is (one time pull-to-refresh shouldn't be bothering)
- Can't disagree too much, it shouldn't be too bothering indeed.
- Then again, in trying to think as a non-tech user, I wonder if they'll get scared not having any orders shown after an app update... And how quickly would they find pull-to-refresh to get their soul back into their body... 😅 🤷
FYI: I think personally this was they first time I used pull-to-refresh on this screen, but can't be too sure, thinking that the order screen got auto-refreshed for me every time I visit this screen, again, not sure... 🤔
move the data from WellSql to Room database before removing the table (maybe worth experimenting with a solution for this as we'll have to do it anyway for SiteModel)
Maybe this is indeed worth experimenting and get some initial feedback on the process... 🤔
request summaries fetch if database has orders, but not summaries (it'll be one-time case, only after initial run after this migration)
Interesting idea, maybe that would work... 🤔
I'll check how time-consuming would be the second point .
👍 and btw, maybe it's a good time to ask someone from the product team for some extra feedback on that, wdyt? 💭
.../fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/dao/OrderSummaryDao.kt
Show resolved
Hide resolved
.../fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/dao/OrderSummaryDao.kt
Outdated
Show resolved
Hide resolved
...luxc-plugin/src/test/java/org/wordpress/android/fluxc/persistence/dao/OrderSummaryDaoTest.kt
Show resolved
Hide resolved
Btw @wzieba , maybe this here and me being just unlucky: p1752505897072599-slack-C02TDTD1GCX 🤷 PS: Will try again tomorrow... 🤞 |
I was thinking about test for this method, but rather to verify if it really runs in a transaction - I wasn't sure that |
…es in `OrderSummaryDao`
👋 @wzieba !
I just reviewed this
@Test
fun `given more than 200 order IDs when getOrderSummaries is called then it chunks input and returns all results in a single transaction`() =
runTest {
val orderSummaries = (1..250).asOrderSummaries(siteId)
dao.upsertOrderSummaries(orderSummaries)
val remoteIds = orderSummaries.map(WCOrderSummaryModel::orderId)
// Call your method that chunks with a for loop and is annotated with @Transaction
val result = dao.getOrderSummaries(siteId, remoteIds)
assertChunked()
assertThat(result).containsExactlyInAnyOrderElementsOf(orderSummaries)
}
private fun assertChunked() {
val expectedFirstChunk = createExpectedQuery(200)
val expectedSecondChunk = createExpectedQuery(50)
val normalizedLogs = logs.lines()
.map { it.trim() }
.filter { it.isNotEmpty() }
.joinToString("\n")
assertThat(normalizedLogs).contains(
buildString {
appendLine(expectedFirstChunk)
appendLine(expectedSecondChunk)
appendLine("TRANSACTION SUCCESSFUL")
appendLine("END TRANSACTION")
}
)
} |
Closes: AINFRA-558
Description
This PR migrates
WCOrderSummary
fromWellSql
toRoom
Steps to reproduce
Testing information
Tools
>Smooth generator
Images/gif
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.