@@ -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