mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 13:44:54 +00:00
Merge pull request #181 from johndoe6345789/codex/add-inflight-flag-to-autosyncmanager
Add in-flight/pending guards to AutoSyncManager to avoid concurrent syncs
This commit is contained in:
@@ -20,6 +20,8 @@ class AutoSyncManager {
|
||||
private timer: ReturnType<typeof setTimeout> | null = null
|
||||
private lastSyncTime = 0
|
||||
private changeCounter = 0
|
||||
private inFlight = false
|
||||
private pendingSync = false
|
||||
private dispatch: any = null
|
||||
|
||||
configure(config: Partial<AutoSyncConfig>) {
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user