perf(pglite): filter artist roles by jsonb containment

After the post-scan ANALYZE the planner probed library_artist once per
artist for the role filter written as stats->'role'->>'m' IS NOT NULL:
29,602 lookups at 3.8 ms each, 116 s for the artist list on roy. The
containment form (stats @> '{"role": {}}') is served by the GIN index:
0.2 s for the same list.
This commit is contained in:
Deluan 2026-09-05 03:54:12 -04:00
commit 943beae278

View file

@ -163,7 +163,8 @@ func NewArtistRepository(ctx context.Context, db dbx.Builder) model.ArtistReposi
func roleFilter(_ string, role any) Sqlizer {
if role, ok := role.(string); ok {
if _, ok := model.AllRoles[role]; ok {
return Expr("library_artist.stats->'" + role + "'->>'m' IS NOT NULL")
// Containment is served by the GIN index on stats; the ->> form forces a row-by-row probe.
return Expr("library_artist.stats @> ?::jsonb", `{"`+role+`": {}}`)
}
}
return Eq{"1": 2}