[HIGH] Replace O(n) .find() linear scans with Map lookups in database.ts #36

Closed
opened 2026-06-09 00:03:13 +00:00 by Mark · 0 comments
Owner

Locations: backend/src/database.ts across getUserById, getSubscriptionById, etc.

Problem: All lookups use .find() on arrays, which is O(n). Combined with the full-file reads on every call, this compounds the performance problem.

Impact: Linear scan becomes a bottleneck as user/subscription count grows.

Fix: Build Map<string, User> keyed by id and by email at startup; update on mutations. O(n) → O(1).

Effort: Included in CRITICAL database cache fix

**Locations:** `backend/src/database.ts` across `getUserById`, `getSubscriptionById`, etc. **Problem:** All lookups use `.find()` on arrays, which is O(n). Combined with the full-file reads on every call, this compounds the performance problem. **Impact:** Linear scan becomes a bottleneck as user/subscription count grows. **Fix:** Build `Map<string, User>` keyed by `id` and by `email` at startup; update on mutations. O(n) → O(1). **Effort:** Included in CRITICAL database cache fix
Mark 2026-06-09 00:03:13 +00:00
  • closed this issue
  • added the
    bug
    label
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/subvault#36
No description provided.