--- id: ML-169.2 title: "Phase 4: Performance low-hanging fruit audit" status: To Do assignee: [] created_date: "2026-05-08 08:59" updated_date: "2026-05-11 06:46" labels: - audit - ready dependencies: [] references: - lib/music_library_web/live/stats_live/index.ex - lib/music_library_web/live_helpers/index_actions.ex - lib/music_library_web/live_helpers/record_actions.ex - .agents/skills/query-reporter/SKILL.md parent_task_id: ML-169 priority: medium --- ## Description Identify unnecessary DB queries, redundant full-stream reloads, server round trips that could be client-side, missing optimistic UI opportunities, and blocking mount work that could be deferred. Use QueryReporter skill to capture SQL traces for key page loads as evidence. Key pre-flagged areas: - StatsLive.Index: 5 synchronous queries in mount (TTFB impact) - Display toggle (grid/list): full FTS query when CSS-only suffices - ScrobbleRulesLive + OnlineStoreTemplateLive: redundant stream_insert + immediate full reload - ScrobbledTracksLive + StatsLive: full stream reset on every scrobble batch instead of incremental insert - Search inputs: verify phx-debounce is set ## Acceptance Criteria - [ ] #1 SQL traces captured via QueryReporter for /collection, /collection/:id, /stats, /artists/:id - [ ] #2 Stream reset audit complete: every stream(:name, data, reset: true) call site evaluated for incremental-update alternatives - [ ] #3 Display toggle (grid/list) evaluated: confirmed whether CSS-only toggle can replace full DB reload - [ ] #4 StatsLive.Index mount blocking work quantified: 5 queries identified, assign_async feasibility assessed - [ ] #5 Search input debounce verified: phx-debounce attribute presence checked on all search forms - [ ] #6 Optimistic UI opportunities identified for delete, form save, toggle operations - [ ] #7 N+1 audit complete: handle_params, stream rendering, and LiveComponent Repo calls checked - [ ] #8 Findings report written as a Backlog.md document with file:line references, severity ratings, and fix recommendations