fix: address code review findings
This commit is contained in:
@@ -44,12 +44,30 @@ func SyncArtistDiscography(
|
||||
return nil, fmt.Errorf("sync artist discography: cache check failed: %w", err)
|
||||
}
|
||||
|
||||
// Step 2: If we have cached data, return it.
|
||||
// Step 2: If we have cached data, return it. Re-apply the per-artist type
|
||||
// toggles even on a cache hit so user changes to ignore_singles /
|
||||
// ignore_compilations take effect without waiting for cache expiry.
|
||||
// (Status/type inclusion was already applied when the rows were first
|
||||
// synced and stored, so only the toggles can change.)
|
||||
if len(cachedReleases) > 0 {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, fmt.Errorf("sync artist discography: %w", err)
|
||||
}
|
||||
return cachedReleases, nil
|
||||
opts, err := getArtistFilterOptions(db, artistID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sync artist discography: read artist filter options: %w", err)
|
||||
}
|
||||
filtered := cachedReleases[:0]
|
||||
for _, r := range cachedReleases {
|
||||
if opts.IgnoreSingles && r.Type == "Single" {
|
||||
continue
|
||||
}
|
||||
if opts.IgnoreCompilations && r.Type == "Compilation" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
// Step 3: Cache miss — fetch from MusicBrainz API.
|
||||
@@ -137,11 +155,12 @@ func SyncArtistDiscography(
|
||||
|
||||
// getArtistFilterOptions reads per-artist type filtering preferences.
|
||||
// Defaults to no filtering if artist_settings row doesn't exist.
|
||||
func getArtistFilterOptions(db *database.DB, artistMBID string) (FilterOptions, error) {
|
||||
// artistID is the Navidrome artist ID (artist_settings.id), not the MusicBrainz ID.
|
||||
func getArtistFilterOptions(db *database.DB, artistID string) (FilterOptions, error) {
|
||||
var opts FilterOptions
|
||||
err := db.Conn().QueryRow(
|
||||
"SELECT COALESCE(ignore_singles, 0), COALESCE(ignore_compilations, 0) FROM artist_settings WHERE id = ?",
|
||||
artistMBID,
|
||||
artistID,
|
||||
).Scan(&opts.IgnoreSingles, &opts.IgnoreCompilations)
|
||||
if err == sql.ErrNoRows {
|
||||
return opts, nil
|
||||
|
||||
Reference in New Issue
Block a user