Skip to content

Conversation

@samiuelson
Copy link
Contributor

@samiuelson samiuelson commented Nov 6, 2025

WOOMOB-1573

Description

This PR removes dependency on WCProductStore from WooPosProductsRemoteDataSource::getVariationById. Instead of looking for variation in WCProductStore, it switches to in-memory variations cache used in POS, and falls back to the rest client in case the cache doesn't hold the variation.

Before, the getVariationById was using WCProductStore (used by store management) to get variation instance in POS Totals screen. This was incorrect, because the POS, in case local catalog is disabled, uses in-memory cache to render items, and WCProductStore is not really a good fit there because it is not synced in any way with the in-memory variations cache in POS.

Test Steps

  1. Open a store not eligible for local catalog (e.g. 1000+ items)
  2. Add variation items to Cart
  3. Check out and collect payment

Smoke test POS, focusing on the Totals and Checkout screens.

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.

This commit refactors the `getVariationById` method in `WooPosProductsDataSource` to prioritize fetching product variations from the cache.

Key changes:
- If a variation is found in the cache, it is returned immediately without a network request.
- If the variation is not in the cache, but other variations for the same product exist, a network request is triggered to fetch all variations for that product. The cache is then updated with the fresh data.
- If the product's variations cache is empty, the method returns null to avoid unnecessary network calls.
- New unit tests have been added to cover these scenarios, including cache hits, cache misses, and network failures.
@samiuelson samiuelson added this to the 23.7 milestone Nov 6, 2025
@samiuelson samiuelson added the Bug label Nov 6, 2025
@samiuelson samiuelson requested a review from Copilot November 6, 2025 15:59
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 adds enhanced caching logic for the getVariationById method in WooPosProductsRemoteDataSource. The implementation now checks the cache before making remote calls and refreshes the entire variation cache if a requested variation is not found but the cache already contains other variations for that product.

  • Implements cache-first logic for variation retrieval
  • Adds automatic cache refresh when variations exist but the requested one is not cached
  • Returns null without remote call when cache is empty (indicating no variations exist)

Reviewed Changes

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

File Description
WooPosProductsDataSource.kt Implements new caching logic in getVariationById to check cache first, refresh from remote if variation not found but cache has variations, and return null for empty cache
WooPosProductsRemoteDataSourceTest.kt Adds comprehensive test coverage for the new caching behavior including cache hit, cache miss with refresh, empty cache, error handling, and cache update scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 6, 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
Commit3e41172
Direct Downloadwoocommerce-wear-prototype-build-pr14918-3e41172.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 6, 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
Commit3e41172
Direct Downloadwoocommerce-prototype-build-pr14918-3e41172.apk

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 38.35%. Comparing base (3692a44) to head (3e41172).

Files with missing lines Patch % Lines
...os/home/items/products/WooPosProductsDataSource.kt 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14918      +/-   ##
============================================
+ Coverage     38.33%   38.35%   +0.01%     
- Complexity    10146    10147       +1     
============================================
  Files          2145     2145              
  Lines        121313   121324      +11     
  Branches      16653    16656       +3     
============================================
+ Hits          46500    46528      +28     
+ Misses        70088    70070      -18     
- Partials       4725     4726       +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 marked this pull request as ready for review November 6, 2025 17:12
@samiuelson samiuelson requested review from kidinov and malinajirka and removed request for malinajirka November 6, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants