-
Notifications
You must be signed in to change notification settings - Fork 135
[Woo POS][Local Catalog] Skip manual one-time sync on site switch if it's not needed #14864
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
[Woo POS][Local Catalog] Skip manual one-time sync on site switch if it's not needed #14864
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #14864 +/- ##
=========================================
Coverage 38.27% 38.27%
- Complexity 10117 10119 +2
=========================================
Files 2140 2140
Lines 121101 121115 +14
Branches 16599 16602 +3
=========================================
+ Hits 46346 46358 +12
- Misses 70046 70047 +1
- Partials 4709 4710 +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 refactors the triggerManualFullCatalogSync() method to check sync requirements before triggering a full catalog sync, preventing unnecessary sync operations when the catalog is already up to date or when local catalog is disabled.
- Added
WooPosFullSyncStatusCheckerdependency to determine if sync is actually needed - Modified sync trigger logic to conditionally execute based on sync requirement status
- Enhanced logging with context-specific messages for different sync requirement scenarios
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-full-sync-on-site-switch
malinajirka
left a comment
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 working on this @samiuelson!
I'd like to propose an alternative approach and hear your thoughts about it. I'm thinking it might be easier to follow the code, if we had these checks within the worker instead of having them in the scheduler for two reasons:
- Single source of truth - skipping sync because the data are up to date is similar to skipping it because POS is inactive, and this logic currently lives in the worker itself.
- Skipping sync when the check sync requirements fails feels off to me - I believe we should retry it in such case. The worker handles this scenario already, since we run
retry()on an unexpected error. However, this PR doesn't handle this scenario I believe.
No matter which approach we decide to go with, I have a couple more thoughts:
- We skip when sync is
NotRequired=> however,NotRequiredis returned for any site that hasn't been synced in 0-6.999 days. Is this intentional or should we run it even if it has been run more than 24 hours ago? logger.d("Manual full sync skipped: Catalog is up to date")feels slightly misleading, I'd suggesting updating the log toCatalog was updated on xyz.. Wdyt?
…-full-sync-on-site-switch
Moves the logic for checking if a full catalog sync is required from the `WooPosLocalCatalogSyncScheduler` to the `WooPosLocalCatalogSyncWorker`. This change simplifies the scheduler by making it responsible only for enqueuing the sync work, while the worker itself now determines if the sync should proceed or be skipped based on the current status.
…-do-not-run-full-sync-on-site-switch' into woomob-1327-woo-poslocal-catalog-do-not-run-full-sync-on-site-switch
…-full-sync-on-site-switch
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
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-full-sync-on-site-switch
…-do-not-run-full-sync-on-site-switch' into woomob-1327-woo-poslocal-catalog-do-not-run-full-sync-on-site-switch
|
Thank you for thorough review, @malinajirka!
I agree. I addressed this in: 9f2a174
IMO this is a bug. I addressed it in a separate PR on top of this PR's feature branch: #14894. Please let me know if you agree.
I improved this within 9f2a174 as well. |
malinajirka
left a comment
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 @samiuelson! It works as expected, I've left a couple non-blocking comments.
|
|
||
| checkSyncRequirement()?.let { return it } | ||
|
|
||
| val site = isCatalogSyncSupported() ?: return Result.failure() |
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.
Is this check still needed when we are using the checker? Seems like there is some duplication in the status checks, wdyt?
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.
| } | ||
|
|
||
| @Suppress("ReturnCount") | ||
| private suspend fun checkSyncRequirement(): Result? { |
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.
It'd be nice to add unit tests for this logic, wdyt?
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.
Added: 12d1651
WOOMOB-1327
Description
This PR refactors the triggerManualFullCatalogSync() method to check sync requirements before triggering a full catalog sync, preventing unnecessary sync operations when the catalog is already up to date or when the local catalog is disabled.
Test Steps
The feature can be tested by switching back and forth between sites and observing if the full sync is performed.
Images/gif
N/A
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.