[OPTIMIZATION] Database & Query Performance - src/lib/db.ts #54

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

Critical Issues (7)

  1. getUpcomingEvents: Full table scan + JS filter instead of indexed range query

    • Current: db.dateEvents.toArray() + db.people.toArray() + JS filter
    • Fix: Add compound index [personId+date], use where("date").between()
    • Impact: 10-100x faster for large datasets
  2. getFamilyEventsForHousehold: Full scan + JS filter on participants.personId

    • Fix: Add index on participants.personId or denormalize
  3. getUpcomingFamilyEvents: Full scan + JS filter on date

    • Fix: Use where("date").between()
  4. getOverduePeople: Loads all people + JS filter

    • Fix: Composite index on [lastContact, contactFrequencyGoal]
  5. searchPeople: Full scan with complex string matching

    • Fix: Add search index / precomputed tokens
  6. getPeopleByTag: Full scan on array field

    • Fix: Denormalize with junction table + index
  7. deletePerson: 4 sequential deletes

    • Fix: Promise.all parallel deletes

High Issues (2)

  1. Missing compound indexes for common query patterns
  2. Multiple .toArray() loads entire tables into memory

Medium Issues (2)

  1. Linear find() for person by ID - use Map
  2. getUpcomingEvents sorts in JS - let IndexedDB sort via index
## Critical Issues (7) 1. **getUpcomingEvents**: Full table scan + JS filter instead of indexed range query - Current: `db.dateEvents.toArray()` + `db.people.toArray()` + JS filter - Fix: Add compound index `[personId+date]`, use `where("date").between()` - Impact: 10-100x faster for large datasets 2. **getFamilyEventsForHousehold**: Full scan + JS filter on `participants.personId` - Fix: Add index on `participants.personId` or denormalize 3. **getUpcomingFamilyEvents**: Full scan + JS filter on date - Fix: Use `where("date").between()` 4. **getOverduePeople**: Loads all people + JS filter - Fix: Composite index on `[lastContact, contactFrequencyGoal]` 5. **searchPeople**: Full scan with complex string matching - Fix: Add search index / precomputed tokens 6. **getPeopleByTag**: Full scan on array field - Fix: Denormalize with junction table + index 7. **deletePerson**: 4 sequential deletes - Fix: `Promise.all` parallel deletes ## High Issues (2) 8. Missing compound indexes for common query patterns 9. Multiple `.toArray()` loads entire tables into memory ## Medium Issues (2) 10. Linear `find()` for person by ID - use Map 11. `getUpcomingEvents` sorts in JS - let IndexedDB sort via index
Mark 2026-06-14 13:10:09 +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#54
No description provided.