feat(library): Missing files says why each track waits, and can forget or export it
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m26s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m29s
release / android (push) Successful in 4m43s
release / Build signed APK (push) Successful in 5m1s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped

- The missing list carries each track's disc and track number, its
  recording and release-group MBIDs, the Collection queue its file was
  removed from, and the admin who removed it.
- POST /api/admin/library/missing/forget deletes waiting tracks for good,
  tidying away an album or artist they leave empty, and writes a
  track_forget audit row naming each. It is all or nothing: a track that
  has its file again is refused with 409 track_has_file.
- GET /api/admin/library/missing.csv exports every waiting track (artist,
  album, disc, track, title, MBIDs, why, since) to hand to whatever finds
  music.
- DELETE /api/admin/tracks/{id} is retired. No client called it; its
  service becomes tracks.Service.ForgetTracks.

Grimoire #7744 (milestone 635).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 18:34:01 -05:00
co-authored by Claude Opus 5.5
parent 9462052625
commit 492eb2fb9a
16 changed files with 621 additions and 558 deletions
+78 -11
View File
@@ -528,12 +528,21 @@ SELECT t.id,
albums.title AS album_title,
artists.id AS artist_id,
artists.name AS artist_name,
t.disc_number,
t.track_number,
t.mbid,
albums.release_group_mbid,
-- Why the track waits: the Collection queue its file was removed from,
-- and who removed it. NULL reason means the scan found the file gone.
t.removed_reason,
remover.username AS removed_by_name,
-- Cast is load-bearing: without it sqlc infers the correlated
-- subquery as interface{} and the Go layer loses the timestamp type.
(SELECT MAX(pe.started_at) FROM play_events pe WHERE pe.track_id = t.id)::timestamptz AS last_played_at
FROM tracks t
JOIN albums ON albums.id = t.album_id
JOIN artists ON artists.id = t.artist_id
LEFT JOIN users remover ON remover.id = t.removed_by
WHERE t.missing_since IS NOT NULL
ORDER BY directory, t.disc_number NULLS FIRST, t.track_number NULLS FIRST, t.title
LIMIT $2 OFFSET $1
@@ -545,17 +554,23 @@ type ListMissingTracksParams struct {
}
type ListMissingTracksRow struct {
ID pgtype.UUID
Title string
FilePath string
Directory string
MissingSince pgtype.Timestamptz
DurationMs int32
AlbumID pgtype.UUID
AlbumTitle string
ArtistID pgtype.UUID
ArtistName string
LastPlayedAt pgtype.Timestamptz
ID pgtype.UUID
Title string
FilePath string
Directory string
MissingSince pgtype.Timestamptz
DurationMs int32
AlbumID pgtype.UUID
AlbumTitle string
ArtistID pgtype.UUID
ArtistName string
DiscNumber *int32
TrackNumber *int32
Mbid *string
ReleaseGroupMbid *string
RemovedReason *string
RemovedByName *string
LastPlayedAt pgtype.Timestamptz
}
// The admin review surface for files the scan could not find.
@@ -590,6 +605,12 @@ func (q *Queries) ListMissingTracks(ctx context.Context, arg ListMissingTracksPa
&i.AlbumTitle,
&i.ArtistID,
&i.ArtistName,
&i.DiscNumber,
&i.TrackNumber,
&i.Mbid,
&i.ReleaseGroupMbid,
&i.RemovedReason,
&i.RemovedByName,
&i.LastPlayedAt,
); err != nil {
return nil, err
@@ -946,6 +967,52 @@ func (q *Queries) ListTracksMissingMbidWithPath(ctx context.Context, limit int32
return items, nil
}
const lockTracksForForget = `-- name: LockTracksForForget :many
SELECT id, album_id, title, file_path, missing_since
FROM tracks
WHERE id = ANY($1::uuid[])
ORDER BY id
FOR UPDATE
`
type LockTracksForForgetRow struct {
ID pgtype.UUID
AlbumID pgtype.UUID
Title string
FilePath string
MissingSince pgtype.Timestamptz
}
// Locks the tracks an admin asked to forget, for the forget's transaction,
// and returns what it re-checks: every one must still exist and still be
// missing. A track whose file came back since the page was read is playing
// again and is not forgotten.
func (q *Queries) LockTracksForForget(ctx context.Context, ids []pgtype.UUID) ([]LockTracksForForgetRow, error) {
rows, err := q.db.Query(ctx, lockTracksForForget, ids)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockTracksForForgetRow
for rows.Next() {
var i LockTracksForForgetRow
if err := rows.Scan(
&i.ID,
&i.AlbumID,
&i.Title,
&i.FilePath,
&i.MissingSince,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markTracksEmptied = `-- name: MarkTracksEmptied :exec
UPDATE tracks
SET emptied_at = missing_since
+20
View File
@@ -261,6 +261,17 @@ UPDATE tracks
WHERE id = ANY(sqlc.arg(ids)::uuid[])
AND missing_since IS NOT NULL;
-- name: LockTracksForForget :many
-- Locks the tracks an admin asked to forget, for the forget's transaction,
-- and returns what it re-checks: every one must still exist and still be
-- missing. A track whose file came back since the page was read is playing
-- again and is not forgotten.
SELECT id, album_id, title, file_path, missing_since
FROM tracks
WHERE id = ANY(sqlc.arg(ids)::uuid[])
ORDER BY id
FOR UPDATE;
-- name: ListMissingTracks :many
-- The admin review surface for files the scan could not find.
--
@@ -284,12 +295,21 @@ SELECT t.id,
albums.title AS album_title,
artists.id AS artist_id,
artists.name AS artist_name,
t.disc_number,
t.track_number,
t.mbid,
albums.release_group_mbid,
-- Why the track waits: the Collection queue its file was removed from,
-- and who removed it. NULL reason means the scan found the file gone.
t.removed_reason,
remover.username AS removed_by_name,
-- Cast is load-bearing: without it sqlc infers the correlated
-- subquery as interface{} and the Go layer loses the timestamp type.
(SELECT MAX(pe.started_at) FROM play_events pe WHERE pe.track_id = t.id)::timestamptz AS last_played_at
FROM tracks t
JOIN albums ON albums.id = t.album_id
JOIN artists ON artists.id = t.artist_id
LEFT JOIN users remover ON remover.id = t.removed_by
WHERE t.missing_since IS NOT NULL
ORDER BY directory, t.disc_number NULLS FIRST, t.track_number NULLS FIRST, t.title
LIMIT sqlc.arg(page_limit) OFFSET sqlc.arg(page_offset);