Skip to content

Commit c8ab269

Browse files
committed
Don’t perform incremental sync during a full sync
1 parent b86ecd7 commit c8ab269

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
105105
throw POSCatalogSyncError.shouldNotSync
106106
}
107107

108-
switch fullSyncStateModel.state[siteID] {
109-
case .syncStarted, .initialSyncStarted:
108+
if await fullSyncInProgress(for: siteID) {
110109
DDLogInfo("⚠️ POSCatalogSyncCoordinator: Sync already in progress for site \(siteID)")
111110
throw POSCatalogSyncError.syncAlreadyInProgress(siteID: siteID)
112-
default:
113-
break
114111
}
115112

116113
let isFirstSync = await lastFullSyncDate(for: siteID) == nil
@@ -199,6 +196,19 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
199196
return shouldSync
200197
}
201198

199+
private func fullSyncInProgress(for siteID: Int64) async -> Bool {
200+
switch fullSyncStateModel.state[siteID] {
201+
case .syncStarted, .initialSyncStarted:
202+
return true
203+
default:
204+
return false
205+
}
206+
}
207+
208+
private func ongoingSyncInProgress(for siteID: Int64) async -> Bool {
209+
ongoingIncrementalSyncs.contains(siteID)
210+
}
211+
202212
/// Performs an incremental sync if applicable based on sync conditions
203213
/// - Parameters:
204214
/// - siteID: The site ID to sync catalog for
@@ -213,11 +223,16 @@ public actor POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
213223
return
214224
}
215225

216-
if ongoingIncrementalSyncs.contains(siteID) {
226+
if await ongoingSyncInProgress(for: siteID) {
217227
DDLogInfo("⚠️ POSCatalogSyncCoordinator: Incremental sync already in progress for site \(siteID)")
218228
throw POSCatalogSyncError.syncAlreadyInProgress(siteID: siteID)
219229
}
220230

231+
if await fullSyncInProgress(for: siteID) {
232+
DDLogInfo("⚠️ POSCatalogSyncCoordinator: Full sync already in progress for site \(siteID)")
233+
throw POSCatalogSyncError.syncAlreadyInProgress(siteID: siteID)
234+
}
235+
221236
guard let lastFullSyncDate = await lastFullSyncDate(for: siteID) else {
222237
return
223238
}

0 commit comments

Comments
 (0)