diff --git a/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs b/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs index b3af8b7a8..2cd0bc2a8 100644 --- a/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs @@ -46,7 +46,8 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests .BuildNew(); _id++; - _artistMetadataRepo.Insert(artist); + _artistMetadataRepo.Insert(metadata); + artist.ArtistMetadataId = metadata.Id; _artistRepo.Insert(artist); } diff --git a/src/NzbDrone.Core/Music/AddArtistService.cs b/src/NzbDrone.Core/Music/AddArtistService.cs index c2b1fc745..7de16ab1e 100644 --- a/src/NzbDrone.Core/Music/AddArtistService.cs +++ b/src/NzbDrone.Core/Music/AddArtistService.cs @@ -87,11 +87,9 @@ namespace NzbDrone.Core.Music } // add metadata - _artistMetadataRepository.UpsertMany(artistsToAdd); - - _logger.Debug("metadata id 1 {0}", string.Join(", ", artistsToAdd.Select(x => x.Metadata.Value.Id))); - _logger.Debug("metadata id 2 {0}", string.Join(", ", artistsToAdd.Select(x => x.ArtistMetadataId))); - + _artistMetadataRepository.UpsertMany(artistsToAdd.Select(x => x.Metadata.Value).ToList()); + artistsToAdd.ForEach(x => x.ArtistMetadataId = x.Metadata.Value.Id); + return _artistService.AddArtists(artistsToAdd); } diff --git a/src/NzbDrone.Core/Music/ArtistMetadataRepository.cs b/src/NzbDrone.Core/Music/ArtistMetadataRepository.cs index c999019d0..2890f4dee 100644 --- a/src/NzbDrone.Core/Music/ArtistMetadataRepository.cs +++ b/src/NzbDrone.Core/Music/ArtistMetadataRepository.cs @@ -8,15 +8,8 @@ namespace NzbDrone.Core.Music { public interface IArtistMetadataRepository : IBasicRepository { - Artist Insert(Artist artist); - List InsertMany(List artists); - Artist Update(Artist artist); - Artist Upsert(Artist artist); - void UpdateMany(List artists); - ArtistMetadata FindById(string foreignArtistId); List FindById(List foreignIds); bool UpsertMany(List artists); - bool UpsertMany(List artists); } public class ArtistMetadataRepository : BasicRepository, IArtistMetadataRepository @@ -29,62 +22,6 @@ namespace NzbDrone.Core.Music _logger = logger; } - public Artist Insert(Artist artist) - { - Insert(artist.Metadata.Value); - artist.ArtistMetadataId = artist.Metadata.Value.Id; - return artist; - } - - public List InsertMany(List artists) - { - InsertMany(artists.Select(x => x.Metadata.Value).ToList()); - artists.ForEach(x => x.ArtistMetadataId = x.Metadata.Value.Id); - - return artists; - } - - public Artist Update(Artist artist) - { - Update(artist.Metadata.Value); - return artist; - } - - public Artist Upsert(Artist artist) - { - var existing = FindById(artist.Metadata.Value.ForeignArtistId); - if (existing != null) - { - artist.ArtistMetadataId = existing.Id; - artist.Metadata.Value.Id = existing.Id; - Update(artist); - } - else - { - Insert(artist); - } - _logger.Debug("Upserted metadata with ID {0}", artist.Id); - return artist; - } - - public bool UpsertMany(List artists) - { - var result = UpsertMany(artists.Select(x => x.Metadata.Value).ToList()); - artists.ForEach(x => x.ArtistMetadataId = x.Metadata.Value.Id); - - return result; - } - - public void UpdateMany(List artists) - { - UpdateMany(artists.Select(x => x.Metadata.Value).ToList()); - } - - public ArtistMetadata FindById(string foreignArtistId) - { - return Query.Where(a => a.ForeignArtistId == foreignArtistId).SingleOrDefault(); - } - public List FindById(List foreignIds) { return Query.Where($"[ForeignArtistId] IN ('{string.Join("','", foreignIds)}')").ToList();