From 6b90c7b2557b5d3a375de572d6429627f5aeeb97 Mon Sep 17 00:00:00 2001 From: jubnl Date: Tue, 5 May 2026 20:08:02 +0200 Subject: [PATCH] refactor: make syncAll manual-only via offline settings tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- client/src/store/authStore.ts | 4 ---- client/src/sync/syncTriggers.ts | 13 ++++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/client/src/store/authStore.ts b/client/src/store/authStore.ts index 8d8c342d..6237cd6d 100644 --- a/client/src/store/authStore.ts +++ b/client/src/store/authStore.ts @@ -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()( 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()( 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()( error: null, }) connect() - tripSyncManager.syncAll().catch(console.error) useSystemNoticeStore.getState().fetch() return data } catch (err: unknown) { diff --git a/client/src/sync/syncTriggers.ts b/client/src/sync/syncTriggers.ts index 2c84afe1..7680fcfc 100644 --- a/client/src/sync/syncTriggers.ts +++ b/client/src/sync/syncTriggers.ts @@ -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 | 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. */