refactor: make syncAll manual-only via offline settings tab

Remove automatic syncAll() calls on login, MFA login, register, and the
window 'online' event. Background bundle sync was the primary cause of
request storms that slowed down initial page loads. Mutation flushing on
reconnect is preserved — only the expensive trip-bundle sync is removed
from auto-triggers.
This commit is contained in:
jubnl
2026-05-05 20:08:02 +02:00
parent 443ae7cb19
commit 6b90c7b255
2 changed files with 6 additions and 11 deletions
-4
View File
@@ -4,7 +4,6 @@ import { authApi } from '../api/client'
import { connect, disconnect } from '../api/websocket'
import type { User } from '../types'
import { getApiErrorMessage } from '../types'
import { tripSyncManager } from '../sync/tripSyncManager'
import { clearAll } from '../db/offlineDb'
import { useSystemNoticeStore } from './systemNoticeStore.js'
@@ -100,7 +99,6 @@ export const useAuthStore = create<AuthState>()(
error: null,
})
connect()
tripSyncManager.syncAll().catch(console.error)
if (!data.user?.must_change_password) {
useSystemNoticeStore.getState().fetch()
}
@@ -124,7 +122,6 @@ export const useAuthStore = create<AuthState>()(
error: null,
})
connect()
tripSyncManager.syncAll().catch(console.error)
if (!data.user?.must_change_password) {
useSystemNoticeStore.getState().fetch()
}
@@ -148,7 +145,6 @@ export const useAuthStore = create<AuthState>()(
error: null,
})
connect()
tripSyncManager.syncAll().catch(console.error)
useSystemNoticeStore.getState().fetch()
return data
} catch (err: unknown) {
+6 -7
View File
@@ -1,19 +1,19 @@
/**
* Sync triggers — register event listeners that flush the mutation queue
* and/or run a full trip sync based on the connectivity trigger source.
* based on the connectivity trigger source.
*
* Trigger matrix:
* window 'online' → flush mutations + full syncAll (network truly back)
* window 'online' → flush mutations (network truly back)
* visibilitychange visible → flush mutations only (avoid hammering server on tab switch)
* periodic 30s → flush mutations only
* WS reconnect → flush mutations only (no syncAll — avoids rate-limiter
* on server restart / socket timeout while already online)
* WS reconnect → flush mutations only
*
* Full trip sync (syncAll) is manual-only via the Offline settings tab.
*
* Call `registerSyncTriggers()` once on app mount.
* Call `unregisterSyncTriggers()` on unmount / logout.
*/
import { mutationQueue } from './mutationQueue'
import { tripSyncManager } from './tripSyncManager'
import { setPreReconnectHook } from '../api/websocket'
const PERIODIC_MS = 30_000
@@ -21,10 +21,9 @@ const PERIODIC_MS = 30_000
let _intervalId: ReturnType<typeof setInterval> | null = null
let _registered = false
/** Network came back — flush mutations AND re-seed Dexie for all cacheable trips. */
/** Network came back — flush any pending mutations. */
function onOnline() {
mutationQueue.flush().catch(console.error)
tripSyncManager.syncAll().catch(console.error)
}
/** Tab became visible — flush only; don't trigger a potentially expensive syncAll. */