Skip to content

Conversation

samiuelson
Copy link
Contributor

@samiuelson samiuelson commented Oct 2, 2025

WOOMOB-1412

Description

The goal of PR is to improve the reliability of the full sync of POS local catalog.
The full sync is scheduled to be performed every 24h, at night. However, in case the device was turned off at night, the sync may not succeed. To handle such case, this PR adds:

  1. Keeping track of the last full sync timestamp
  2. Checking if the last full sync is overdue
  3. Scheduling one-time, instant full sync in case the nightly full sync is overdue

⚠️ In case the full sync was never performed before, it should be obligatory before entering the POS. This will be added in the next PR: WOOMOB-1414.

⚠️ Do not merge until the base branch is trunk.

Steps to reproduce

Testing information

Verify that WooPosLocalCatalogSyncWorker is being scheduled and completes when the app is opened, in case previous one was not done within last 24h.

The tests that have been performed

Above.

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 changed the title Woomob 1412 woo poslocal catalog full sync overdue handling [Woo POS][Local Catalog] Full sync overdue handling Oct 2, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 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
Commiteba015c
Direct Downloadwoocommerce-wear-prototype-build-pr14678-eba015c.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 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
Commiteba015c
Direct Downloadwoocommerce-prototype-build-pr14678-eba015c.apk

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.42%. Comparing base (36df697) to head (eba015c).
⚠️ Report is 5 commits behind head on trunk.

Files with missing lines Patch % Lines
...ocalcatalog/WooPosPerformInitialCatalogFullSync.kt 64.58% 29 Missing and 5 partials ⚠️
...os/util/datastore/WooPosSyncTimestampRepository.kt 0.00% 13 Missing ⚠️
...erce/android/ui/woopos/home/WooPosHomeViewModel.kt 50.00% 11 Missing and 1 partial ⚠️
...commerce/android/ui/woopos/home/WooPosHomeState.kt 33.33% 6 Missing ⚠️
.../store/pos/localcatalog/WooPosLocalCatalogStore.kt 0.00% 4 Missing ⚠️
...oopos/util/datastore/WooPosSyncTimestampManager.kt 0.00% 3 Missing ⚠️
...n/kotlin/com/woocommerce/android/AppInitializer.kt 0.00% 2 Missing ⚠️
...mmerce/android/ui/woopos/home/WooPosHomeUIEvent.kt 0.00% 1 Missing ⚠️
.../woopos/localcatalog/WooPosFullSyncCheckUseCase.kt 97.14% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14678      +/-   ##
============================================
+ Coverage     38.38%   38.42%   +0.03%     
- Complexity     9836     9854      +18     
============================================
  Files          2094     2096       +2     
  Lines        116801   116988     +187     
  Branches      15633    15667      +34     
============================================
+ Hits          44837    44950     +113     
- Misses        67801    67868      +67     
- Partials       4163     4170       +7     

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

…n-pos-splash' into woomob-1412-woo-poslocal-catalog-full-sync-overdue-handling
@samiuelson samiuelson added the type: task An internally driven task. label Oct 2, 2025
@samiuelson samiuelson added this to the 23.4 milestone Oct 2, 2025
@samiuelson samiuelson requested a review from kidinov October 2, 2025 16:42
@samiuelson samiuelson marked this pull request as ready for review October 2, 2025 16:43
@samiuelson samiuelson requested review from malinajirka and removed request for kidinov October 3, 2025 07:11
@samiuelson samiuelson added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Oct 3, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 3, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@malinajirka malinajirka modified the milestones: 23.4, 23.5 Oct 3, 2025
Base automatically changed from woomob-1405-woo-poslocal-catalog-run-incremental-sync-on-pos-splash to trunk October 3, 2025 11:05
@samiuelson samiuelson marked this pull request as draft October 3, 2025 11:33
@samiuelson samiuelson removed the request for review from malinajirka October 3, 2025 11:33
…overdue-handling

# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/WooPosItemsScreen.kt
@samiuelson samiuelson requested a review from Copilot October 3, 2025 13:21
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 enhances the reliability of POS local catalog full sync by implementing overdue handling. Previously, if a device was turned off during the scheduled nightly full sync, the sync could fail indefinitely. This change adds tracking and automatic recovery for overdue syncs.

Key changes:

  • Added timestamp tracking for full sync completion
  • Implemented overdue sync detection (24-hour threshold)
  • Added automatic background sync triggering when sync is overdue
  • Moved incremental sync from splash screen to POS home initialization

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
WooPosLocalCatalogStore.kt Added product count method for catalog validation
WooPosProductsDao.kt Added SQL query to count products in local database
WooPosSyncTimestampRepository.kt Added methods to store and retrieve full sync completion timestamps
WooPosSyncTimestampManager.kt Added wrapper methods for full sync timestamp management
WooPosPerformInitialCatalogFullSync.kt New use case handling initial sync with overdue detection logic
WooPosFullSyncCheckUseCase.kt New use case for checking and triggering overdue syncs on app start
WooPosLocalCatalogSyncWorker.kt Updated to store completion timestamp after successful sync
WooPosSplashViewModel.kt Removed incremental sync from splash screen initialization
WooPosHomeViewModel.kt Added catalog sync state management and incremental sync triggering
WooPosHomeScreen.kt Added sync overlay UI components for progress and error states
AppInitializer.kt Added overdue sync check on app startup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

suspend fun getFullSyncLastCompletedTimestamp(): Long? {
val key = buildSiteSpecificKey(FULL_SYNC_TIMESTAMP_KEY)
return if (key != null) {
dataStore.data.first()[key]?.toLong()
Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The toLong() call can throw a NumberFormatException if the stored string is not a valid long. Consider using toLongOrNull() and handling the null case.

Copilot uses AI. Check for mistakes.

emit(WooPosFullSyncStatus.InProgress)

var workerStillRunning = true
while (workerStillRunning) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

💡 I'll investigate if it's possible to replace while with getWorkInfoById.

@samiuelson samiuelson changed the title [Woo POS][Local Catalog] Full sync overdue handling [Woo POS][Local Catalog] Full sync missing/overdue handling Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: do not merge Dependent on another PR, ready for review but not ready for merge. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants