fix: address fourth code review findings
- Fix FK constraint violation in SyncArtistDiscography: delete notifications_sent rows before external_releases to prevent constraint failure when re-syncing artists with prior notifications. - Implement per-artist type filtering: FilterReleaseGroups now accepts FilterOptions with IgnoreSingles/IgnoreCompilations flags, read from artist_settings table via getArtistFilterOptions. - Fix inconsistent error wrapping: GetExternalRelease now wraps errors with fmt.Errorf like all other functions in the package; updated test to use errors.Is for sql.ErrNoRows check. - Add tests: FilterReleaseGroups ignore singles/compilations, SyncArtistDiscography per-artist type filtering, and FK-safe resync.
This commit is contained in:
@@ -82,10 +82,17 @@ func (c *MusicBrainzClient) GetArtistReleaseGroups(ctx context.Context, artistMB
|
||||
return allGroups, nil
|
||||
}
|
||||
|
||||
// FilterOptions holds per-artist type filtering preferences.
|
||||
type FilterOptions struct {
|
||||
IgnoreSingles bool
|
||||
IgnoreCompilations bool
|
||||
}
|
||||
|
||||
// FilterReleaseGroups applies status and type filtering to a list of release groups.
|
||||
// It excludes Bootleg, Promotion, and Pseudo-Release statuses.
|
||||
// It includes only Album, Single, EP, and Compilation types.
|
||||
func FilterReleaseGroups(groups []ReleaseGroup) []ReleaseGroup {
|
||||
// It includes only Album, Single, EP, and Compilation types, unless the type
|
||||
// is disabled via FilterOptions.
|
||||
func FilterReleaseGroups(groups []ReleaseGroup, opts FilterOptions) []ReleaseGroup {
|
||||
var filtered []ReleaseGroup
|
||||
for _, rg := range groups {
|
||||
if IsStatusExcluded(rg.Status) {
|
||||
@@ -94,6 +101,12 @@ func FilterReleaseGroups(groups []ReleaseGroup) []ReleaseGroup {
|
||||
if !IsTypeIncluded(rg.Type) {
|
||||
continue
|
||||
}
|
||||
if opts.IgnoreSingles && rg.Type == "Single" {
|
||||
continue
|
||||
}
|
||||
if opts.IgnoreCompilations && rg.Type == "Compilation" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, rg)
|
||||
}
|
||||
return filtered
|
||||
|
||||
Reference in New Issue
Block a user