mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 23:32:41 +00:00
Fixed: Artist FindById Should Find OldIds
This commit is contained in:
parent
250d79b5bb
commit
81ffc4e28f
3 changed files with 61 additions and 18 deletions
|
@ -19,7 +19,6 @@ public class ArtistRepositoryFixture : DbTest<ArtistRepository, Artist>
|
|||
{
|
||||
private ArtistRepository _artistRepo;
|
||||
private ArtistMetadataRepository _artistMetadataRepo;
|
||||
private int _id = 1;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -28,20 +27,25 @@ public void Setup()
|
|||
_artistMetadataRepo = Mocker.Resolve<ArtistMetadataRepository>();
|
||||
}
|
||||
|
||||
private void AddArtist(string name)
|
||||
private void AddArtist(string name, string foreignId, List<string> oldIds = null)
|
||||
{
|
||||
if (oldIds == null)
|
||||
{
|
||||
oldIds = new List<string>();
|
||||
}
|
||||
|
||||
var metadata = Builder<ArtistMetadata>.CreateNew()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.Name = name)
|
||||
.With(a=> a.OldForeignArtistIds = oldIds)
|
||||
.BuildNew();
|
||||
|
||||
var artist = Builder<Artist>.CreateNew()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.Metadata = metadata)
|
||||
.With(a => a.CleanName = Parser.Parser.CleanArtistName(name))
|
||||
.With(a => a.ForeignArtistId = _id.ToString())
|
||||
.With(a => a.ForeignArtistId = foreignId)
|
||||
.BuildNew();
|
||||
_id++;
|
||||
|
||||
_artistMetadataRepo.Insert(metadata);
|
||||
artist.ArtistMetadataId = metadata.Id;
|
||||
|
@ -50,8 +54,8 @@ private void AddArtist(string name)
|
|||
|
||||
private void GivenArtists()
|
||||
{
|
||||
AddArtist("The Black Eyed Peas");
|
||||
AddArtist("The Black Keys");
|
||||
AddArtist("The Black Eyed Peas", "d5be5333-4171-427e-8e12-732087c6b78e");
|
||||
AddArtist("The Black Keys", "d15721d8-56b4-453d-b506-fc915b14cba2", new List<string> { "6f2ed437-825c-4cea-bb58-bf7688c6317a" });
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -100,14 +104,35 @@ public void should_find_artist_in_db_by_name(string name)
|
|||
artist.Name.Should().Be(name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_find_artist_in_by_id()
|
||||
{
|
||||
GivenArtists();
|
||||
var artist = _artistRepo.FindById("d5be5333-4171-427e-8e12-732087c6b78e");
|
||||
|
||||
artist.Should().NotBeNull();
|
||||
artist.ForeignArtistId.Should().Be("d5be5333-4171-427e-8e12-732087c6b78e");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_find_artist_in_by_old_id()
|
||||
{
|
||||
GivenArtists();
|
||||
var artist = _artistRepo.FindById("6f2ed437-825c-4cea-bb58-bf7688c6317a");
|
||||
|
||||
artist.Should().NotBeNull();
|
||||
artist.Name.Should().Be("The Black Keys");
|
||||
artist.ForeignArtistId.Should().Be("d15721d8-56b4-453d-b506-fc915b14cba2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_find_artist_if_multiple_artists_have_same_name()
|
||||
{
|
||||
GivenArtists();
|
||||
|
||||
string name = "Alice Cooper";
|
||||
AddArtist(name);
|
||||
AddArtist(name);
|
||||
AddArtist(name, "ee58c59f-8e7f-4430-b8ca-236c4d3745ae");
|
||||
AddArtist(name, "4d7928cd-7ed2-4282-8c29-c0c9f966f1bd");
|
||||
|
||||
_artistRepo.All().Should().HaveCount(4);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace NzbDrone.Core.ImportLists
|
|||
{
|
||||
public class ImportListSyncService : IExecute<ImportListSyncCommand>
|
||||
{
|
||||
private readonly IImportListStatusService _importListStatusService;
|
||||
private readonly IImportListFactory _importListFactory;
|
||||
private readonly IImportListExclusionService _importListExclusionService;
|
||||
private readonly IFetchAndParseImportList _listFetcherAndParser;
|
||||
|
@ -25,8 +24,7 @@ public class ImportListSyncService : IExecute<ImportListSyncCommand>
|
|||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ImportListSyncService(IImportListStatusService importListStatusService,
|
||||
IImportListFactory importListFactory,
|
||||
public ImportListSyncService(IImportListFactory importListFactory,
|
||||
IImportListExclusionService importListExclusionService,
|
||||
IFetchAndParseImportList listFetcherAndParser,
|
||||
ISearchForNewAlbum albumSearchService,
|
||||
|
@ -36,7 +34,6 @@ public ImportListSyncService(IImportListStatusService importListStatusService,
|
|||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
_importListStatusService = importListStatusService;
|
||||
_importListFactory = importListFactory;
|
||||
_importListExclusionService = importListExclusionService;
|
||||
_listFetcherAndParser = listFetcherAndParser;
|
||||
|
@ -118,22 +115,33 @@ private List<Album> ProcessReports(List<ImportListItemInfo> reports)
|
|||
|
||||
// Check to see if artist in DB
|
||||
var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId);
|
||||
|
||||
|
||||
// TODO: Rework this for albums when we can add albums seperate from Artists
|
||||
// (If list contains albums we should not break for an existing artist, we should add new albums that are not in DB)
|
||||
if (existingArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected, Artist Exists in DB", report.ArtistMusicBrainzId, report.Artist);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check to see if artist excluded
|
||||
var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault();
|
||||
|
||||
if (excludedArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Append Artist if not already in DB or already on add list
|
||||
if (existingArtist == null && excludedArtist == null && artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
|
||||
if (artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
|
||||
{
|
||||
var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
|
||||
|
||||
artistsToAdd.Add(new Artist
|
||||
{
|
||||
Metadata = new ArtistMetadata {
|
||||
Metadata = new ArtistMetadata
|
||||
{
|
||||
ForeignArtistId = report.ArtistMusicBrainzId,
|
||||
Name = report.Artist
|
||||
},
|
||||
|
@ -143,7 +151,8 @@ private List<Album> ProcessReports(List<ImportListItemInfo> reports)
|
|||
MetadataProfileId = importList.MetadataProfileId,
|
||||
Tags = importList.Tags,
|
||||
AlbumFolder = true,
|
||||
AddOptions = new AddArtistOptions {
|
||||
AddOptions = new AddArtistOptions
|
||||
{
|
||||
SearchForMissingAlbums = monitored,
|
||||
Monitored = monitored,
|
||||
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
|
||||
|
@ -160,7 +169,7 @@ private List<Album> ProcessReports(List<ImportListItemInfo> reports)
|
|||
|
||||
_addArtistService.AddArtists(artistsToAdd);
|
||||
|
||||
var message = string.Format("Import List Sync Completed. Reports found: {0}, Reports grabbed: {1}", reports.Count, processed.Count);
|
||||
var message = string.Format("Import List Sync Completed. Items found: {0}, Artists added: {1}", reports.Count, artistsToAdd.Count);
|
||||
|
||||
_logger.ProgressInfo(message);
|
||||
|
||||
|
|
|
@ -31,7 +31,16 @@ public bool ArtistPathExists(string path)
|
|||
|
||||
public Artist FindById(string foreignArtistId)
|
||||
{
|
||||
return Query.Where<ArtistMetadata>(m => m.ForeignArtistId == foreignArtistId).SingleOrDefault();
|
||||
var artist = Query.Where<ArtistMetadata>(m => m.ForeignArtistId == foreignArtistId).SingleOrDefault();
|
||||
|
||||
if (artist == null)
|
||||
{
|
||||
var id = "\"" + foreignArtistId + "\"";
|
||||
artist = Query.Where<ArtistMetadata>(x => x.OldForeignArtistIds.Contains(id))
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
return artist;
|
||||
}
|
||||
|
||||
public Artist FindByName(string cleanName)
|
||||
|
|
Loading…
Reference in a new issue