Skip to content

Conversation

@samiuelson
Copy link
Contributor

@samiuelson samiuelson commented Oct 30, 2025

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

  • 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.

@samiuelson samiuelson added type: task An internally driven task. feature: point of sale POS project labels Oct 30, 2025
@samiuelson samiuelson added this to the 23.6 milestone Oct 30, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 30, 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 NameWooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitd63f43d
Direct Downloadwoocommerce-wear-prototype-build-pr14864-d63f43d.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 30, 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 NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitd63f43d
Direct Downloadwoocommerce-prototype-build-pr14864-d63f43d.apk

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.27%. Comparing base (00a1930) to head (d63f43d).
⚠️ Report is 62 commits behind head on trunk.

Files with missing lines Patch % Lines
...oopos/localcatalog/WooPosLocalCatalogSyncWorker.kt 86.36% 1 Missing and 2 partials ⚠️
...os/localcatalog/WooPosLocalCatalogSyncScheduler.kt 0.00% 1 Missing ⚠️
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.
📢 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.

@samiuelson samiuelson requested a review from Copilot October 30, 2025 13:14
Copy link
Contributor

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 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 WooPosFullSyncStatusChecker dependency 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.

@samiuelson samiuelson modified the milestones: 23.6, 23.7 Oct 30, 2025
@samiuelson samiuelson marked this pull request as ready for review October 31, 2025 15:58
@malinajirka malinajirka self-assigned this Nov 3, 2025
Copy link
Contributor

@malinajirka malinajirka left a 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:

  1. 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.
  2. 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:

  1. We skip when sync is NotRequired => however, NotRequired is 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?
  2. logger.d("Manual full sync skipped: Catalog is up to date") feels slightly misleading, I'd suggesting updating the log to Catalog was updated on xyz.. Wdyt?

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
@samiuelson samiuelson requested a review from Copilot November 4, 2025 10:28
Copy link
Contributor

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

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.

@samiuelson
Copy link
Contributor Author

samiuelson commented Nov 4, 2025

Thank you for thorough review, @malinajirka!

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:

  1. 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.
  2. 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.

I agree. I addressed this in: 9f2a174

No matter which approach we decide to go with, I have a couple more thoughts:

  1. We skip when sync is NotRequired => however, NotRequired is 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?

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.

  1. logger.d("Manual full sync skipped: Catalog is up to date") feels slightly misleading, I'd suggesting updating the log to Catalog was updated on xyz.. Wdyt?

I improved this within 9f2a174 as well.

Copy link
Contributor

@malinajirka malinajirka left a 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()
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in f0726ab and f95953e

}

@Suppress("ReturnCount")
private suspend fun checkSyncRequirement(): Result? {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added: 12d1651

@samiuelson samiuelson enabled auto-merge November 5, 2025 11:43
@samiuelson samiuelson merged commit d41963c into trunk Nov 5, 2025
18 checks passed
@samiuelson samiuelson deleted the woomob-1327-woo-poslocal-catalog-do-not-run-full-sync-on-site-switch branch November 5, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: point of sale POS project type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants