mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-26 15:52:42 +00:00
Fixed: Don't find album when multiple albums have the same name
This commit is contained in:
parent
c500f7b943
commit
36f34a4113
2 changed files with 24 additions and 41 deletions
|
@ -13,7 +13,6 @@ public class AlbumRepositoryFixture : DbTest<AlbumService, Album>
|
||||||
private Artist _artist;
|
private Artist _artist;
|
||||||
private Album _album;
|
private Album _album;
|
||||||
private Album _albumSpecial;
|
private Album _albumSpecial;
|
||||||
private Album _albumSimilar;
|
|
||||||
private AlbumRelease _release;
|
private AlbumRelease _release;
|
||||||
private AlbumRepository _albumRepo;
|
private AlbumRepository _albumRepo;
|
||||||
private ReleaseRepository _releaseRepo;
|
private ReleaseRepository _releaseRepo;
|
||||||
|
@ -48,6 +47,7 @@ public void Setup()
|
||||||
ForeignAlbumId = "1",
|
ForeignAlbumId = "1",
|
||||||
CleanTitle = "anthology",
|
CleanTitle = "anthology",
|
||||||
Artist = _artist,
|
Artist = _artist,
|
||||||
|
ArtistMetadataId = _artist.ArtistMetadataId,
|
||||||
AlbumType = "",
|
AlbumType = "",
|
||||||
AlbumReleases = new List<AlbumRelease> {_release },
|
AlbumReleases = new List<AlbumRelease> {_release },
|
||||||
};
|
};
|
||||||
|
@ -63,7 +63,7 @@ public void Setup()
|
||||||
ForeignAlbumId = "2",
|
ForeignAlbumId = "2",
|
||||||
CleanTitle = "",
|
CleanTitle = "",
|
||||||
Artist = _artist,
|
Artist = _artist,
|
||||||
ArtistId = _artist.ArtistMetadataId,
|
ArtistMetadataId = _artist.ArtistMetadataId,
|
||||||
AlbumType = "",
|
AlbumType = "",
|
||||||
AlbumReleases = new List<AlbumRelease>
|
AlbumReleases = new List<AlbumRelease>
|
||||||
{
|
{
|
||||||
|
@ -77,24 +77,6 @@ public void Setup()
|
||||||
|
|
||||||
_albumRepo.Insert(_albumSpecial);
|
_albumRepo.Insert(_albumSpecial);
|
||||||
|
|
||||||
_albumSimilar = new Album
|
|
||||||
{
|
|
||||||
Title = "ANThology2",
|
|
||||||
ForeignAlbumId = "3",
|
|
||||||
CleanTitle = "anthology2",
|
|
||||||
Artist = _artist,
|
|
||||||
ArtistId = _artist.ArtistMetadataId,
|
|
||||||
AlbumType = "",
|
|
||||||
AlbumReleases = new List<AlbumRelease>
|
|
||||||
{
|
|
||||||
new AlbumRelease
|
|
||||||
{
|
|
||||||
ForeignReleaseId = "fake id 2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -139,6 +121,26 @@ public void should_not_find_album_in_db_by_incorrect_title(string title)
|
||||||
album.Should().BeNull();
|
album.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_find_album_when_two_albums_have_same_name()
|
||||||
|
{
|
||||||
|
var albums = Builder<Album>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(x => x.Id = 0)
|
||||||
|
.With(x => x.Artist = _artist)
|
||||||
|
.With(x => x.ArtistMetadataId = _artist.ArtistMetadataId)
|
||||||
|
.With(x => x.Title = "Weezer")
|
||||||
|
.With(x => x.CleanTitle = "weezer")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_albumRepo.InsertMany(albums);
|
||||||
|
|
||||||
|
var album = _albumRepo.FindByTitle(_artist.ArtistMetadataId, "Weezer");
|
||||||
|
|
||||||
|
_albumRepo.All().Should().HaveCount(4);
|
||||||
|
album.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_find_album_in_db_by_partial_releaseid()
|
public void should_not_find_album_in_db_by_partial_releaseid()
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Languages;
|
using NzbDrone.Core.Languages;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music
|
namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
|
@ -15,9 +16,7 @@ public interface IAlbumRepository : IBasicRepository<Album>
|
||||||
{
|
{
|
||||||
List<Album> GetAlbums(int artistId);
|
List<Album> GetAlbums(int artistId);
|
||||||
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
|
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
|
||||||
Album FindByName(string cleanTitle);
|
|
||||||
Album FindByTitle(int artistMetadataId, string title);
|
Album FindByTitle(int artistMetadataId, string title);
|
||||||
Album FindByArtistAndName(string artistName, string cleanTitle);
|
|
||||||
Album FindById(string foreignId);
|
Album FindById(string foreignId);
|
||||||
List<Album> FindById(List<string> foreignIds);
|
List<Album> FindById(List<string> foreignIds);
|
||||||
PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec);
|
PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec);
|
||||||
|
@ -328,13 +327,6 @@ public void SetMonitored(IEnumerable<int> ids, bool monitored)
|
||||||
mapper.ExecuteNonQuery(sql);
|
mapper.ExecuteNonQuery(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Album FindByName(string cleanTitle)
|
|
||||||
{
|
|
||||||
cleanTitle = cleanTitle.ToLowerInvariant();
|
|
||||||
|
|
||||||
return Query.Where(s => s.CleanTitle == cleanTitle).SingleOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Album FindByTitle(int artistMetadataId, string title)
|
public Album FindByTitle(int artistMetadataId, string title)
|
||||||
{
|
{
|
||||||
var cleanTitle = Parser.Parser.CleanArtistName(title);
|
var cleanTitle = Parser.Parser.CleanArtistName(title);
|
||||||
|
@ -344,18 +336,7 @@ public Album FindByTitle(int artistMetadataId, string title)
|
||||||
|
|
||||||
return Query.Where(s => s.CleanTitle == cleanTitle || s.Title == title)
|
return Query.Where(s => s.CleanTitle == cleanTitle || s.Title == title)
|
||||||
.AndWhere(s => s.ArtistMetadataId == artistMetadataId)
|
.AndWhere(s => s.ArtistMetadataId == artistMetadataId)
|
||||||
.FirstOrDefault();
|
.ExclusiveOrDefault();
|
||||||
}
|
|
||||||
|
|
||||||
public Album FindByArtistAndName(string artistName, string cleanTitle)
|
|
||||||
{
|
|
||||||
var cleanArtistName = Parser.Parser.CleanArtistName(artistName);
|
|
||||||
cleanTitle = cleanTitle.ToLowerInvariant();
|
|
||||||
|
|
||||||
return Query.Join<Album, Artist>(JoinType.Inner, rg => rg.Artist, (rg, artist) => rg.ArtistMetadataId == artist.ArtistMetadataId)
|
|
||||||
.Where<Artist>(artist => artist.CleanName == cleanArtistName)
|
|
||||||
.Where<Album>(album => album.CleanTitle == cleanTitle)
|
|
||||||
.SingleOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Album FindAlbumByRelease(string albumReleaseId)
|
public Album FindAlbumByRelease(string albumReleaseId)
|
||||||
|
|
Loading…
Reference in a new issue