[OPTIMIZATION] Zustand Store - Mutations & Initialization - src/lib/store.ts #55

Closed
opened 2026-06-06 20:41:43 +00:00 by Mark · 0 comments
Owner

Critical Issues (2)

  1. Seed data: 31 sequential await addX() calls (18 people + 6 dateEvents + 7 interactions)

    • Fix: Promise.all + bulkAdd
    • Impact: 10-30x faster seed
  2. Every mutation triggers full reloads: createPerson/updatePerson/deletePerson all call loadPeople(), loadInteractions(), loadDateEvents(), loadGifts()

    • Fix: Optimistic updates - update local state directly after DB write
    • Impact: 50-100x faster mutations

High Issues (3)

  1. CRUD operations: Sequential loadPeople() + loadInteractions() + loadDateEvents() + loadGifts()

    • Fix: Promise.all parallel loads
  2. App initialization: 6 sequential Preferences.get calls

    • Fix: Promise.all parallel fetches
    • Impact: 5-6x faster startup
  3. deletePerson: Triggers 4 full reloads

    • Fix: Targeted optimistic delete

Medium Issues (1)

  1. No timeout on DB operations - wrap with Promise.race + 3s timeout

Low Issues (1)

  1. Math.random() for toast IDs - use counter or crypto.randomUUID()
## Critical Issues (2) 1. **Seed data**: 31 sequential `await addX()` calls (18 people + 6 dateEvents + 7 interactions) - Fix: `Promise.all` + `bulkAdd` - Impact: 10-30x faster seed 2. **Every mutation triggers full reloads**: `createPerson`/`updatePerson`/`deletePerson` all call `loadPeople()`, `loadInteractions()`, `loadDateEvents()`, `loadGifts()` - Fix: Optimistic updates - update local state directly after DB write - Impact: 50-100x faster mutations ## High Issues (3) 3. **CRUD operations**: Sequential `loadPeople()` + `loadInteractions()` + `loadDateEvents()` + `loadGifts()` - Fix: `Promise.all` parallel loads 4. **App initialization**: 6 sequential `Preferences.get` calls - Fix: `Promise.all` parallel fetches - Impact: 5-6x faster startup 5. **deletePerson**: Triggers 4 full reloads - Fix: Targeted optimistic delete ## Medium Issues (1) 6. **No timeout on DB operations** - wrap with `Promise.race` + 3s timeout ## Low Issues (1) 7. **Math.random() for toast IDs** - use counter or `crypto.randomUUID()`
Mark 2026-06-14 13:00:51 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/kimi_agent_kin_app_sync#55
No description provided.