fix(subsonic): albums, folders and search list only what the listener can play

getAlbum, getMusicDirectory and search2/3 ignored the listener's quarantine
and listed missing files, which an app then failed to stream; song counts
counted both. They now pass the listener and leave out missing files, as
the mixes already did. Subsonic can't mark a song unplayable, so leaving it
out is how the native apps' greyed-out row comes across.

Song search filters in SQL (SearchPlayableTracks), so a library sync paging
through search3 never gets a short page that reads as the end. Album song
counts come from one query for the whole page (CountPlayableTracksByAlbums)
instead of one per album.

tracks.sql also drops CountTracksByArtist, which nothing called; see the
next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 22:02:00 -05:00
co-authored by Claude Opus 5.5
parent d0675e1817
commit 1ff4bc8258
5 changed files with 296 additions and 37 deletions
+29 -6
View File
@@ -83,6 +83,35 @@ WHERE title ILIKE '%' || $1::text || '%'
ORDER BY title, id
LIMIT $3 OFFSET $4;
-- name: SearchPlayableTracks :many
-- Subsonic's song search: tracks whose title matches $1 that the listener
-- $2 can play, so neither a missing file nor one they quarantined. Subsonic
-- has no way to mark a song unplayable, and apps page through the whole
-- library with this, so the filter is here rather than after the LIMIT:
-- a short page reads to an app as the end of the results.
SELECT * FROM tracks
WHERE title ILIKE '%' || sqlc.arg(query)::text || '%'
AND missing_since IS NULL
AND NOT EXISTS (
SELECT 1 FROM quarantine q
WHERE q.user_id = sqlc.arg(user_id) AND q.track_id = tracks.id
)
ORDER BY title, id
LIMIT sqlc.arg(row_limit) OFFSET sqlc.arg(row_offset);
-- name: CountPlayableTracksByAlbums :many
-- How many of each album's tracks the listener $2 can play: present on
-- disk and not quarantined by them. An album with none is absent.
SELECT album_id, count(*)::int AS track_count
FROM tracks
WHERE album_id = ANY(sqlc.arg(album_ids)::uuid[])
AND missing_since IS NULL
AND NOT EXISTS (
SELECT 1 FROM quarantine q
WHERE q.user_id = sqlc.arg(user_id) AND q.track_id = tracks.id
)
GROUP BY album_id;
-- name: CountTracksMatching :one
-- $1 = title query, $2 = user_id (NULL to skip quarantine filter).
SELECT COUNT(*) FROM tracks
@@ -129,12 +158,6 @@ WHERE NOT EXISTS (
ORDER BY random()
LIMIT $2;
-- name: CountTracksByArtist :one
-- Used by request-progress reporting to count tracks ingested under a
-- matched artist (sum across all the artist's albums) while a request
-- is still in flight.
SELECT COUNT(*) FROM tracks WHERE artist_id = $1;
-- name: DeleteTrack :one
-- Hard delete with FK cascade. The CASCADE on track_id from
-- play_events / general_likes_tracks / quarantine /