fix n+1 queries in comfortGenerator and deepDiveGenerator (#110)
both generators ran N sequential queries per artist/album. rewritten with ROW_NUMBER() OVER (PARTITION BY ...) to get per-group limits in a single round-trip, preserving existing semantics: - comfortGenerator: up to 2 tracks per artist (was 20 queries → 1) - deepDiveGenerator: up to 5 tracks per album (was 20 queries → 1)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# muzick — overnight fix plan
|
||||
|
||||
## tasks
|
||||
1. **fix N+1 queries** in generators.service.ts (#110, prio:4)
|
||||
2. **fix SSRF guard** in images.routes.ts (#111, prio:3)
|
||||
3. **clean & re-enrich images** (#124, prio:0 — operational)
|
||||
4. **ethos UI migration** (#34, prio:5 — dispatched to ethos-ui agent)
|
||||
|
||||
## 1. N+1 queries
|
||||
|
||||
### comfortGenerator (lines 57-87)
|
||||
current: loops 20 artists, `SELECT ... WHERE object_id = $1` per artist
|
||||
fix: single query with `WHERE cf.object_id = ANY($1::uuid[])` + `unnest` to get per-artist rows back
|
||||
|
||||
### deepDiveGenerator (lines 248-274)
|
||||
current: loops 20 albums, `SELECT ... WHERE t.album_id = $1` per album
|
||||
fix: single query with `WHERE t.album_id = ANY($1::uuid[])` — already batched on artist query
|
||||
|
||||
### verification
|
||||
`comfortGenerator` and `deepDiveGenerator` are tested in `generators.test.ts`
|
||||
Reference in New Issue
Block a user