fix: a file tagged with no release group joins the same-named album its folder holds
release / govulncheck (push) Successful in 16s
release / web (push) Successful in 1m20s
release / go (push) Successful in 1m31s
release / integration (push) Successful in 4m58s
release / android (push) Successful in 5m1s
release / Build signed APK (releases and dev) (push) Successful in 5m14s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 16s
release / Verify release artifacts (tag releases only) (push) Skipped

Under e45561e2 a file with no group tag took the oldest same-named album row,
which left three of Weezer's 1994 bonus tracks on the 2016 album. The lookup
now ranks same-named rows by how many tracks they hold from the file's
folder; tagReadVersion 8 re-places the existing ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 14:44:45 -04:00
co-authored by Claude Opus 5.5
parent e45561e282
commit 210f884b2d
4 changed files with 52 additions and 22 deletions
+19 -7
View File
@@ -72,11 +72,14 @@ func (q *Queries) DeleteAlbumIfEmpty(ctx context.Context, id pgtype.UUID) (Delet
}
const getAlbumByArtistAndTitle = `-- name: GetAlbumByArtistAndTitle :one
SELECT id, title, sort_title, artist_id, release_date, mbid, cover_art_path, created_at, updated_at, cover_art_source, cover_art_sources_version, release_group_mbid FROM albums
WHERE artist_id = $1 AND title = $2
AND ($3::text IS NULL OR release_group_mbid IS NULL
OR release_group_mbid = $3)
ORDER BY (release_group_mbid IS NOT DISTINCT FROM $3) DESC, id
SELECT albums.id, albums.title, albums.sort_title, albums.artist_id, albums.release_date, albums.mbid, albums.cover_art_path, albums.created_at, albums.updated_at, albums.cover_art_source, albums.cover_art_sources_version, albums.release_group_mbid FROM albums
WHERE albums.artist_id = $1 AND albums.title = $2
AND ($3::text IS NULL OR albums.release_group_mbid IS NULL
OR albums.release_group_mbid = $3)
ORDER BY (albums.release_group_mbid IS NOT DISTINCT FROM $3) DESC,
(SELECT count(*) FROM tracks t
WHERE t.album_id = albums.id AND starts_with(t.file_path, $4::text || '/')) DESC,
albums.id
LIMIT 1
`
@@ -84,15 +87,24 @@ type GetAlbumByArtistAndTitleParams struct {
ArtistID pgtype.UUID
Title string
ReleaseGroupMbid *string
Dir string
}
// Scanner uses this for the no-mbid dedupe path: resolve-or-create. An album
// of the same name in another release group is a different album (Weezer's
// six self-titled albums shared one row until 2026-10-20), so a row whose
// group is known and differs is not returned. A row of the file's own group
// comes first, then one with no group yet.
// comes first, then one with no group yet, then the one holding the most
// tracks from the file's folder: a file tagged with no group (a live bonus
// track beside Weezer's 1994 album) belongs with its folder, not the oldest
// row, and a few strays already misfiled do not outvote the folder.
func (q *Queries) GetAlbumByArtistAndTitle(ctx context.Context, arg GetAlbumByArtistAndTitleParams) (Album, error) {
row := q.db.QueryRow(ctx, getAlbumByArtistAndTitle, arg.ArtistID, arg.Title, arg.ReleaseGroupMbid)
row := q.db.QueryRow(ctx, getAlbumByArtistAndTitle,
arg.ArtistID,
arg.Title,
arg.ReleaseGroupMbid,
arg.Dir,
)
var i Album
err := row.Scan(
&i.ID,
+12 -6
View File
@@ -40,12 +40,18 @@ ORDER BY release_date NULLS LAST, sort_title;
-- of the same name in another release group is a different album (Weezer's
-- six self-titled albums shared one row until 2026-10-20), so a row whose
-- group is known and differs is not returned. A row of the file's own group
-- comes first, then one with no group yet.
SELECT * FROM albums
WHERE artist_id = sqlc.arg(artist_id) AND title = sqlc.arg(title)
AND (sqlc.narg(release_group_mbid)::text IS NULL OR release_group_mbid IS NULL
OR release_group_mbid = sqlc.narg(release_group_mbid))
ORDER BY (release_group_mbid IS NOT DISTINCT FROM sqlc.narg(release_group_mbid)) DESC, id
-- comes first, then one with no group yet, then the one holding the most
-- tracks from the file's folder: a file tagged with no group (a live bonus
-- track beside Weezer's 1994 album) belongs with its folder, not the oldest
-- row, and a few strays already misfiled do not outvote the folder.
SELECT albums.* FROM albums
WHERE albums.artist_id = sqlc.arg(artist_id) AND albums.title = sqlc.arg(title)
AND (sqlc.narg(release_group_mbid)::text IS NULL OR albums.release_group_mbid IS NULL
OR albums.release_group_mbid = sqlc.narg(release_group_mbid))
ORDER BY (albums.release_group_mbid IS NOT DISTINCT FROM sqlc.narg(release_group_mbid)) DESC,
(SELECT count(*) FROM tracks t
WHERE t.album_id = albums.id AND starts_with(t.file_path, sqlc.arg(dir)::text || '/')) DESC,
albums.id
LIMIT 1;
-- name: ListAlbumsByArtist :many