-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS][Local Catalog] Check catalog size in sync coordinator #16119
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
Merged
joshheald
merged 6 commits into
trunk
from
woomob-1252-check-eligibility-in-sync-coordinator
Sep 12, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29370f0
Check catalog size before sync
joshheald 9c2e389
Add tests for checking size before sync
joshheald 323cbe4
Allow max catalog size to be passed in
joshheald 69ef11f
Use minimal get requests to get through jetpack
joshheald 61a7497
Don’t expose max catalog size
joshheald cea0e8e
Merge branch 'trunk' into woomob-1252-check-eligibility-in-sync-coord…
joshheald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Modules/Sources/Yosemite/Tools/POS/POSCatalogSizeChecker.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import Foundation | ||
| import Networking | ||
|
|
||
| /// Protocol for checking the size of a remote POS catalog | ||
| public protocol POSCatalogSizeCheckerProtocol { | ||
| /// Checks the size of the remote catalog for the specified site | ||
| /// - Parameter siteID: The site ID to check catalog size for | ||
| /// - Returns: The size information of the catalog | ||
| /// - Throws: Network or parsing errors | ||
| func checkCatalogSize(for siteID: Int64) async throws -> POSCatalogSize | ||
| } | ||
|
|
||
| /// Implementation of catalog size checker that uses the sync remote to get counts | ||
| public struct POSCatalogSizeChecker: POSCatalogSizeCheckerProtocol { | ||
| private let syncRemote: POSCatalogSyncRemoteProtocol | ||
|
|
||
| public init(syncRemote: POSCatalogSyncRemoteProtocol) { | ||
| self.syncRemote = syncRemote | ||
| } | ||
|
|
||
| public func checkCatalogSize(for siteID: Int64) async throws -> POSCatalogSize { | ||
| // Make concurrent requests to get both counts | ||
| async let productCount = syncRemote.getProductCount(siteID: siteID) | ||
| async let variationCount = syncRemote.getProductVariationCount(siteID: siteID) | ||
|
|
||
| do { | ||
| return try await POSCatalogSize( | ||
| productCount: productCount, | ||
| variationCount: variationCount | ||
| ) | ||
| } catch { | ||
| DDLogError( | ||
| "⚠️ Failed to check POS catalog size for site \(siteID): \(error)" | ||
| ) | ||
| throw error | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public struct POSCatalogSize: Equatable { | ||
| /// Number of products in the catalog | ||
| public let productCount: Int | ||
|
|
||
| /// Number of product variations in the catalog | ||
| public let variationCount: Int | ||
|
|
||
| /// Total number of items (products + variations) | ||
| public var totalCount: Int { | ||
| productCount + variationCount | ||
| } | ||
|
|
||
| public init(productCount: Int, variationCount: Int) { | ||
| self.productCount = productCount | ||
| self.variationCount = variationCount | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: the catalog size checker seems like an internal tool within Yosemite, do you foresee this being used in the app layer?
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.
Yes. For example, we'll want to check the size when we decide whether to use the existing approach or the local catalog, which needs to be decided in the app layer.
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.
Given that there are other sync/async conditions for the local catalog feature as in p1757587795454369/1757587788.433699-slack-C070SJRA8DP, I thought we might have another high-level checker for all the conditions (and implement caching if we decide to). So that this class is for internal use in Yosemite. WDYT?