Fixed: Simplify ArtistMetadataRepository

pull/865/head
ta264 5 years ago
parent 0b7a42ee3b
commit 8160f3d84a

@ -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);
}

@ -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);
}

@ -8,15 +8,8 @@ namespace NzbDrone.Core.Music
{
public interface IArtistMetadataRepository : IBasicRepository<ArtistMetadata>
{
Artist Insert(Artist artist);
List<Artist> InsertMany(List<Artist> artists);
Artist Update(Artist artist);
Artist Upsert(Artist artist);
void UpdateMany(List<Artist> artists);
ArtistMetadata FindById(string foreignArtistId);
List<ArtistMetadata> FindById(List<string> foreignIds);
bool UpsertMany(List<ArtistMetadata> artists);
bool UpsertMany(List<Artist> artists);
}
public class ArtistMetadataRepository : BasicRepository<ArtistMetadata>, 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<Artist> InsertMany(List<Artist> 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<Artist> 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<Artist> artists)
{
UpdateMany(artists.Select(x => x.Metadata.Value).ToList());
}
public ArtistMetadata FindById(string foreignArtistId)
{
return Query.Where(a => a.ForeignArtistId == foreignArtistId).SingleOrDefault();
}
public List<ArtistMetadata> FindById(List<string> foreignIds)
{
return Query.Where($"[ForeignArtistId] IN ('{string.Join("','", foreignIds)}')").ToList();

Loading…
Cancel
Save