-
Notifications
You must be signed in to change notification settings - Fork 121
[POS][Local Catalog] Ensure we only run one sync at a time per site #16100
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -768,7 +768,7 @@ private extension MainTabBarController { | |
|
|
||
| // Configure POS catalog sync coordinator for local catalog syncing | ||
| if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleLocalCatalogi1) { | ||
| posCatalogSyncCoordinator = createPOSCatalogSyncCoordinator() | ||
| posCatalogSyncCoordinator = ServiceLocator.posCatalogSyncCoordinator | ||
|
||
| } | ||
|
|
||
| // Configure hub menu tab coordinator once per logged in session potentially with multiple sites. | ||
|
|
@@ -792,15 +792,6 @@ private extension MainTabBarController { | |
| OrdersSplitViewWrapperController(siteID: siteID) | ||
| } | ||
|
|
||
| func createPOSCatalogSyncCoordinator() -> POSCatalogSyncCoordinatorProtocol? { | ||
| guard let credentials = ServiceLocator.stores.sessionManager.defaultCredentials, | ||
| let syncService = POSCatalogFullSyncService(credentials: credentials, grdbManager: ServiceLocator.grdbManager) | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
| return POSCatalogSyncCoordinator(syncService: syncService, grdbManager: ServiceLocator.grdbManager) | ||
| } | ||
|
|
||
| func triggerPOSCatalogSyncIfNeeded(for siteID: Int64) async { | ||
| guard let coordinator = posCatalogSyncCoordinator else { | ||
|
|
@@ -809,14 +800,16 @@ private extension MainTabBarController { | |
|
|
||
| // Check if sync is needed (older than 24 hours) | ||
| let maxAge: TimeInterval = 24 * 60 * 60 | ||
| guard coordinator.shouldPerformFullSync(for: siteID, maxAge: maxAge) else { | ||
| guard await coordinator.shouldPerformFullSync(for: siteID, maxAge: maxAge) else { | ||
| return | ||
| } | ||
|
|
||
| // Perform background sync | ||
| Task.detached { | ||
| do { | ||
| _ = try await coordinator.performFullSync(for: siteID) | ||
| } catch POSCatalogSyncError.syncAlreadyInProgress { | ||
| DDLogInfo("ℹ️ POS catalog sync already in progress for site \(siteID), skipping") | ||
| } catch { | ||
| DDLogError("⚠️ POS catalog sync failed: \(error)") | ||
| } | ||
|
|
||
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.
How about moving it to
shouldPerformFullSync?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.
I think probably better to keep it where it is. There could be some gap between calling
shouldPerformandperform, which would make this check fail.