Skip to content

Commit 61a7497

Browse files
committed
Don’t expose max catalog size
1 parent 69ef11f commit 61a7497

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

Modules/Sources/Yosemite/Tools/POS/POSCatalogSyncCoordinator.swift

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,13 @@ public protocol POSCatalogSyncCoordinatorProtocol {
1616
/// - Returns: True if a sync should be performed
1717
func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval) async -> Bool
1818

19-
/// Determines if a full sync should be performed based on the age of the last sync
20-
/// - Parameters:
21-
/// - siteID: The site ID to check
22-
/// - maxAge: Maximum age before a sync is considered stale
23-
/// - maxCatalogSize: Maximum allowed catalog size for syncing (default: 1000)
24-
/// - Returns: True if a sync should be performed
25-
func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval, maxCatalogSize: Int) async -> Bool
26-
2719
/// Performs an incremental sync if applicable based on sync conditions
2820
/// - Parameters:
2921
/// - siteID: The site ID to sync catalog for
3022
/// - forceSync: Whether to bypass age checks and always sync
3123
/// - Throws: POSCatalogSyncError.syncAlreadyInProgress if a sync is already running for this site
3224
//periphery:ignore - remove ignore comment when incremental sync is integrated with POS
3325
func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool) async throws
34-
35-
/// Performs an incremental sync if applicable based on sync conditions
36-
/// - Parameters:
37-
/// - siteID: The site ID to sync catalog for
38-
/// - forceSync: Whether to bypass age checks and always sync
39-
/// - maxCatalogSize: Maximum allowed catalog size for syncing (default: 1000)
40-
/// - Throws: POSCatalogSyncError.syncAlreadyInProgress if a sync is already running for this site
41-
//periphery:ignore - remove ignore comment when incremental sync is integrated with POS
42-
func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool, maxCatalogSize: Int) async throws
4326
}
4427

4528
public enum POSCatalogSyncError: Error, Equatable {
@@ -51,6 +34,7 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
5134
private let incrementalSyncService: POSCatalogIncrementalSyncServiceProtocol
5235
private let grdbManager: GRDBManagerProtocol
5336
private let maxIncrementalSyncAge: TimeInterval
37+
private let catalogSizeLimit: Int
5438
private let catalogSizeChecker: POSCatalogSizeCheckerProtocol
5539

5640
/// Tracks ongoing full syncs by site ID to prevent duplicates
@@ -62,11 +46,13 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
6246
incrementalSyncService: POSCatalogIncrementalSyncServiceProtocol,
6347
grdbManager: GRDBManagerProtocol,
6448
maxIncrementalSyncAge: TimeInterval = 300,
49+
catalogSizeLimit: Int? = nil,
6550
catalogSizeChecker: POSCatalogSizeCheckerProtocol) {
6651
self.fullSyncService = fullSyncService
6752
self.incrementalSyncService = incrementalSyncService
6853
self.grdbManager = grdbManager
6954
self.maxIncrementalSyncAge = maxIncrementalSyncAge
55+
self.catalogSizeLimit = catalogSizeLimit ?? Constants.defaultSizeLimitForPOSCatalog
7056
self.catalogSizeChecker = catalogSizeChecker
7157
}
7258

@@ -91,17 +77,16 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
9177
DDLogInfo("✅ POSCatalogSyncCoordinator completed full sync for site \(siteID)")
9278
}
9379

94-
public func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval) async -> Bool {
95-
return await shouldPerformFullSync(for: siteID, maxAge: maxAge, maxCatalogSize: 1000)
96-
}
97-
9880
/// Determines if a full sync should be performed based on the age of the last sync
9981
/// - Parameters:
10082
/// - siteID: The site ID to check
10183
/// - maxAge: Maximum age before a sync is considered stale
102-
/// - maxCatalogSize: Maximum allowed catalog size for syncing
10384
/// - Returns: True if a sync should be performed
104-
public func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval, maxCatalogSize: Int) async -> Bool {
85+
public func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval) async -> Bool {
86+
return await shouldPerformFullSync(for: siteID, maxAge: maxAge, maxCatalogSize: catalogSizeLimit)
87+
}
88+
89+
private func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval, maxCatalogSize: Int) async -> Bool {
10590
guard await isCatalogSizeWithinLimit(for: siteID, maxCatalogSize: maxCatalogSize) else {
10691
return false
10792
}
@@ -130,17 +115,16 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
130115
return shouldSync
131116
}
132117

133-
public func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool) async throws {
134-
try await performIncrementalSyncIfApplicable(for: siteID, forceSync: forceSync, maxCatalogSize: 1000)
135-
}
136-
137118
/// Performs an incremental sync if applicable based on sync conditions
138119
/// - Parameters:
139120
/// - siteID: The site ID to sync catalog for
140121
/// - forceSync: Whether to bypass age checks and always sync
141-
/// - maxCatalogSize: Maximum allowed catalog size for syncing
142122
/// - Throws: POSCatalogSyncError.syncAlreadyInProgress if a sync is already running for this site
143-
public func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool, maxCatalogSize: Int) async throws {
123+
public func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool) async throws {
124+
try await performIncrementalSyncIfApplicable(for: siteID, forceSync: forceSync, maxCatalogSize: catalogSizeLimit)
125+
}
126+
127+
private func performIncrementalSyncIfApplicable(for siteID: Int64, forceSync: Bool, maxCatalogSize: Int) async throws {
144128
if ongoingIncrementalSyncs.contains(siteID) {
145129
DDLogInfo("⚠️ POSCatalogSyncCoordinator: Incremental sync already in progress for site \(siteID)")
146130
throw POSCatalogSyncError.syncAlreadyInProgress(siteID: siteID)
@@ -236,3 +220,9 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
236220
}
237221
}
238222
}
223+
224+
private extension POSCatalogSyncCoordinator {
225+
enum Constants {
226+
static let defaultSizeLimitForPOSCatalog = 1000
227+
}
228+
}

0 commit comments

Comments
 (0)