From eb9174c80d8e62bc6e42076d206dff7b321b1d6f Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 18 Jan 2026 18:14:51 +0000 Subject: [PATCH] Add in-flight guard to auto sync --- src/store/middleware/autoSyncMiddleware.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/store/middleware/autoSyncMiddleware.ts b/src/store/middleware/autoSyncMiddleware.ts index 277769c..b8cc1f4 100644 --- a/src/store/middleware/autoSyncMiddleware.ts +++ b/src/store/middleware/autoSyncMiddleware.ts @@ -20,6 +20,8 @@ class AutoSyncManager { private timer: ReturnType | null = null private lastSyncTime = 0 private changeCounter = 0 + private inFlight = false + private pendingSync = false private dispatch: any = null configure(config: Partial) { @@ -68,18 +70,33 @@ class AutoSyncManager { private async performSync() { if (!this.dispatch) return + if (this.inFlight) { + this.pendingSync = true + return + } + this.inFlight = true try { await this.dispatch(syncToFlaskBulk()) this.lastSyncTime = Date.now() this.changeCounter = 0 } catch (error) { console.error('[AutoSync] Sync failed:', error) + } finally { + this.inFlight = false + } + + if (this.pendingSync) { + this.pendingSync = false + await this.performSync() } } trackChange() { this.changeCounter++ + if (this.inFlight) { + this.pendingSync = true + } if (this.changeCounter >= this.config.maxQueueSize && this.config.syncOnChange) { this.performSync()