Skip to content

Conversation

@joshheald
Copy link
Contributor

@joshheald joshheald commented Nov 10, 2025

Part of: WOOMOB-1173

Description

This PR moves full sync downloads using the full catalog file API to use background URLSessions

This is a follow-up on #16048 to bring it up to date with trunk and finish the work.

Note that in this PR, we handle the parsing and database insert when we open POS again. A future PR will use our available background time at the end of the request to move everything to the database.

Also note that background sessions don't work for the polling requests to see when catalog generation is done, which tends to take longer than downloading the catalog. Discussion: p1762799234106449-slack-C070SJRA8DP

Test Steps

Backgrounded testing is tricky, and you can't really do it with the debugger attached. I've found network breakpoints are useful.

  • Use a large catalog store with the catalog generation/file endpoints, e.g. largefuntesting.mystagingwebsite.com
  • Turn on the pointOfSaleCatalogAPI feature flag
  • Set POSLocalCatalogEligibilityService.Constants.defaultCatalogSizeLimit to 100000
  • Set network conditions to something slow, like 3g or 2g. In Proxyman, it's Tools > Network conditions > + then set the host to largefuntesting.mystagingwebsite.com and use the preset profile. Note that this is only wanted for the file download, so no need to do it on public-api.wordpress.com. For these settings, 3g takes about 30s to download, and 2g takes about 2 minutes.
  1. Run the app, then stop it.
  2. Launch the app from the device, not Xcode.
  3. Go to POS > Settings and tap refresh catalog
  4. Watch the requests to /wc/v3/products/catalog, wait for the completed status response with a download URL (this takes a few minutes)
  5. As soon as you see that, background the app
  6. Wait for the download to complete (see Proxyman to check that it has)
  7. Open the app again and go to Menu > Settings > Help and Support > Application logs > Current
  8. Observe that the download completed and was persisted when we opened the app again.

Screenshots


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

jaclync and others added 6 commits August 27, 2025 14:10
…est in the background using `URLSessionConfiguration.background`.
Resolves merge conflicts by integrating background download functionality with trunk's complete catalog sync implementation:

- Updated POSCatalogSyncRemote to use BackgroundDownloadService while preserving trunk's full protocol
- Added cellular data preference support to background downloads
- Updated BackgroundDownloadProtocol and BackgroundDownloadService to accept allowCellular parameter
- Modified MockBackgroundDownloader to track cellular preference in tests
- Merged test suites to cover both background downloads and cellular preference tests

The downloadCatalog method now uses background URLSession with configurable cellular access, maintaining compatibility with trunk's POSCatalogFullSyncService flow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements `application(_:handleEventsForBackgroundURLSession:completionHandler:)` to support background catalog downloads when the app is suspended.

- Handles background URLSession events for catalog download sessions
- Stores completion handler for iOS to call when background tasks complete
- Adds logging for debugging background download lifecycle
- Includes TODO for wiring completion handler to BackgroundDownloadService

This enables the POS catalog sync to continue downloading large catalog files even when the app is suspended or terminated by the system.

Related: WOOMOB-1173

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Resolves "file couldn't be opened" error by ensuring downloaded files persist until parsing completes.

**Problem:**
iOS immediately cleans up the temp file location returned by URLSession delegate after the callback completes, but async/await parsing happens later, causing "file not found" errors.

**Solution:**
- Move downloaded file to managed temp location that persists beyond delegate callback
- Always clean up file after parsing (simplified from conditional cleanup)
- Add better logging for debugging download lifecycle

**Changes:**
- BackgroundDownloadService: Move file to persistent temp location immediately
- POSCatalogSyncRemote: Always clean up downloaded file after parsing

This ensures the file exists when parsing starts while still cleaning up properly after use.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@joshheald joshheald added type: task An internally driven task. feature: POS labels Nov 10, 2025
@joshheald joshheald added this to the 23.7 milestone Nov 10, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 10, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 10, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16337-3980e7e
Version23.6
Bundle IDcom.automattic.alpha.woocommerce
Commit3980e7e
Installation URL78fnv77njum40
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: POS type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants