From 97610a08f8a5a44ca03b6c1ccae699ee2f90fc13 Mon Sep 17 00:00:00 2001 From: Till JS Date: Fri, 10 Apr 2026 18:43:33 +0200 Subject: [PATCH] feat(sync): batched push with PUSH_BATCH_SIZE = 200 Caps each push request to 200 pending changes so a user who was offline for weeks doesn't send a single multi-MB payload. After each successful batch, schedulePush re-triggers to drain the remaining rows in subsequent chunks. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/mana/apps/web/src/lib/data/sync.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/mana/apps/web/src/lib/data/sync.ts b/apps/mana/apps/web/src/lib/data/sync.ts index ef65a6c2b..cf672eb1c 100644 --- a/apps/mana/apps/web/src/lib/data/sync.ts +++ b/apps/mana/apps/web/src/lib/data/sync.ts @@ -459,6 +459,13 @@ export type SyncStatus = 'idle' | 'syncing' | 'error' | 'offline'; // ─── Config ─────────────────────────────────────────────────── const PUSH_DEBOUNCE = 1000; +/** + * Maximum number of pending changes to include in a single push request. + * Prevents multi-MB payloads when a user was offline for weeks and + * accumulated thousands of changes. The push loop re-schedules itself + * after each batch so all changes eventually drain. + */ +const PUSH_BATCH_SIZE = 200; const PULL_INTERVAL = 30_000; const WS_RECONNECT_DELAY = 5000; @@ -662,14 +669,19 @@ export function createUnifiedSync(serverUrl: string, getToken: () => Promise PUSH_BATCH_SIZE; setStatus('syncing'); const startedAt = Date.now();