You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core.Test/Datastore/MarrDataLazyLoadingFixture.cs

339 lines
13 KiB

using FizzWare.NBuilder;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Profiles.Languages;
using NzbDrone.Core.Test.Languages;
using Marr.Data.QGen;
using System.Collections.Generic;
Whole album matching and fingerprinting (#592) * Cache result of GetAllArtists * Fixed: Manual import not respecting album import notifications * Fixed: partial album imports stay in queue, prompting manual import * Fixed: Allow release if tracks are missing * Fixed: Be tolerant of missing/extra "The" at start of artist name * Improve manual import UI * Omit video tracks from DB entirely * Revert "faster test packaging in build.sh" This reverts commit 2723e2a7b86bcbff9051fd2aced07dd807b4bcb7. -u and -T are not supported on macOS * Fix tests on linux and macOS * Actually lint on linux On linux yarn runs scripts with sh not bash so ** doesn't recursively glob * Match whole albums * Option to disable fingerprinting * Rip out MediaInfo * Don't split up things that have the same album selected in manual import * Try to speed up IndentificationService * More speedups * Some fixes and increase power of recording id * Fix NRE when no tags * Fix NRE when some (but not all) files in a directory have missing tags * Bump taglib, tidy up tag parsing * Add a health check * Remove media info setting * Tags -> audioTags * Add some tests where tags are null * Rename history events * Add missing method to interface * Reinstate MediaInfo tags and update info with artist scan Also adds migration to remove old format media info * This file no longer exists * Don't penalise year if missing from tags * Formatting improvements * Use correct system newline * Switch to the netstandard2.0 library to support net 461 * TagLib.File is IDisposable so should be in a using * Improve filename matching and add tests * Neater logging of parsed tags * Fix disk scan tests for new media info update * Fix quality detection source * Fix Inexact Artist/Album match * Add button to clear track mapping * Fix warning * Pacify eslint * Use \ not / * Fix UI updates * Fix media covers Prevent localizing URL propaging back to the metadata object * Reduce database overhead broadcasting UI updates * Relax timings a bit to make test pass * Remove irrelevant tests * Test framework for identification service * Fix PreferMissingToBadMatch test case * Make fingerprinting more robust * More logging * Penalize unknown media format and country * Prefer USA to UK * Allow Data CD * Fix exception if fingerprinting fails for all files * Fix tests * Fix NRE * Allow apostrophes and remove accents in filename aggregation * Address codacy issues * Cope with old versions of fpcalc and suggest upgrade * fpcalc health check passes if fingerprinting disabled * Get the Artist meta with the artist * Fix the mapper so that lazy loaded lists will be populated on Join And therefore we can join TrackFiles on Tracks by default and avoid an extra query * Rename subtitle -> lyric * Tidy up MediaInfoFormatter
5 years ago
using System.Linq;
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
public class MarrDataLazyLoadingFixture : DbTest
{
[SetUp]
public void Setup()
{
var profile = new Profile
{
Name = "Test",
Cutoff = Quality.MP3_320.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
};
var languageProfile = new LanguageProfile
{
Name = "Test",
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
};
profile = Db.Insert(profile);
languageProfile = Db.Insert(languageProfile);
var metadata = Builder<ArtistMetadata>.CreateNew()
.With(v => v.Id = 0)
.Build();
Db.Insert(metadata);
var artist = Builder<Artist>.CreateListOfSize(1)
.All()
.With(v => v.Id = 0)
.With(v => v.ProfileId = profile.Id)
.With(v => v.LanguageProfileId = languageProfile.Id)
.With(v => v.ArtistMetadataId = metadata.Id)
.BuildListOfNew();
Db.InsertMany(artist);
var albums = Builder<Album>.CreateListOfSize(3)
.All()
.With(v => v.Id = 0)
.With(v => v.ArtistMetadataId = metadata.Id)
.BuildListOfNew();
Db.InsertMany(albums);
var releases = new List<AlbumRelease>();
foreach (var album in albums)
{
releases.Add(
Builder<AlbumRelease>.CreateNew()
.With(v => v.Id = 0)
.With(v => v.AlbumId = album.Id)
.With(v => v.ForeignReleaseId = "test" + album.Id)
.Build());
}
Db.InsertMany(releases);
var trackFiles = Builder<TrackFile>.CreateListOfSize(1)
.All()
.With(v => v.Id = 0)
Whole album matching and fingerprinting (#592) * Cache result of GetAllArtists * Fixed: Manual import not respecting album import notifications * Fixed: partial album imports stay in queue, prompting manual import * Fixed: Allow release if tracks are missing * Fixed: Be tolerant of missing/extra "The" at start of artist name * Improve manual import UI * Omit video tracks from DB entirely * Revert "faster test packaging in build.sh" This reverts commit 2723e2a7b86bcbff9051fd2aced07dd807b4bcb7. -u and -T are not supported on macOS * Fix tests on linux and macOS * Actually lint on linux On linux yarn runs scripts with sh not bash so ** doesn't recursively glob * Match whole albums * Option to disable fingerprinting * Rip out MediaInfo * Don't split up things that have the same album selected in manual import * Try to speed up IndentificationService * More speedups * Some fixes and increase power of recording id * Fix NRE when no tags * Fix NRE when some (but not all) files in a directory have missing tags * Bump taglib, tidy up tag parsing * Add a health check * Remove media info setting * Tags -> audioTags * Add some tests where tags are null * Rename history events * Add missing method to interface * Reinstate MediaInfo tags and update info with artist scan Also adds migration to remove old format media info * This file no longer exists * Don't penalise year if missing from tags * Formatting improvements * Use correct system newline * Switch to the netstandard2.0 library to support net 461 * TagLib.File is IDisposable so should be in a using * Improve filename matching and add tests * Neater logging of parsed tags * Fix disk scan tests for new media info update * Fix quality detection source * Fix Inexact Artist/Album match * Add button to clear track mapping * Fix warning * Pacify eslint * Use \ not / * Fix UI updates * Fix media covers Prevent localizing URL propaging back to the metadata object * Reduce database overhead broadcasting UI updates * Relax timings a bit to make test pass * Remove irrelevant tests * Test framework for identification service * Fix PreferMissingToBadMatch test case * Make fingerprinting more robust * More logging * Penalize unknown media format and country * Prefer USA to UK * Allow Data CD * Fix exception if fingerprinting fails for all files * Fix tests * Fix NRE * Allow apostrophes and remove accents in filename aggregation * Address codacy issues * Cope with old versions of fpcalc and suggest upgrade * fpcalc health check passes if fingerprinting disabled * Get the Artist meta with the artist * Fix the mapper so that lazy loaded lists will be populated on Join And therefore we can join TrackFiles on Tracks by default and avoid an extra query * Rename subtitle -> lyric * Tidy up MediaInfoFormatter
5 years ago
.With(v => v.AlbumId = albums[0].Id)
.With(v => v.Quality = new QualityModel())
.BuildListOfNew();
Db.InsertMany(trackFiles);
var tracks = Builder<Track>.CreateListOfSize(10)
.All()
.With(v => v.Id = 0)
.With(v => v.TrackFileId = trackFiles[0].Id)
.With(v => v.AlbumReleaseId = releases[0].Id)
.BuildListOfNew();
Db.InsertMany(tracks);
}
[Test]
public void should_join_artist_when_query_for_albums()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var albums = DataMapper.Query<Album>()
.Join<Album, Artist>(JoinType.Inner, v => v.Artist, (l, r) => l.ArtistMetadataId == r.ArtistMetadataId)
.ToList();
foreach (var album in albums)
{
Assert.IsNotNull(album.Artist);
}
}
[Test]
public void should_lazy_load_profile_if_not_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.Join<Track, AlbumRelease>(JoinType.Inner, v => v.AlbumRelease, (l, r) => l.AlbumReleaseId == r.Id)
.Join<AlbumRelease, Album>(JoinType.Inner, v => v.Album, (l, r) => l.AlbumId == r.Id)
.Join<Album, Artist>(JoinType.Inner, v => v.Artist, (l, r) => l.ArtistMetadataId == r.ArtistMetadataId)
.ToList();
foreach (var track in tracks)
{
Assert.IsTrue(track.AlbumRelease.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.Value.Artist.IsLoaded);
Assert.IsNotNull(track.AlbumRelease.Value.Album.Value.Artist.Value);
Assert.IsFalse(track.AlbumRelease.Value.Album.Value.Artist.Value.Profile.IsLoaded);
Assert.IsFalse(track.AlbumRelease.Value.Album.Value.Artist.Value.LanguageProfile.IsLoaded);
}
}
[Test]
public void should_explicit_load_trackfile_if_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.Join<Track, TrackFile>(JoinType.Inner, v => v.TrackFile, (l, r) => l.TrackFileId == r.Id)
.ToList();
foreach (var track in tracks)
{
Assert.IsFalse(track.Artist.IsLoaded);
Assert.IsTrue(track.TrackFile.IsLoaded);
}
}
Whole album matching and fingerprinting (#592) * Cache result of GetAllArtists * Fixed: Manual import not respecting album import notifications * Fixed: partial album imports stay in queue, prompting manual import * Fixed: Allow release if tracks are missing * Fixed: Be tolerant of missing/extra "The" at start of artist name * Improve manual import UI * Omit video tracks from DB entirely * Revert "faster test packaging in build.sh" This reverts commit 2723e2a7b86bcbff9051fd2aced07dd807b4bcb7. -u and -T are not supported on macOS * Fix tests on linux and macOS * Actually lint on linux On linux yarn runs scripts with sh not bash so ** doesn't recursively glob * Match whole albums * Option to disable fingerprinting * Rip out MediaInfo * Don't split up things that have the same album selected in manual import * Try to speed up IndentificationService * More speedups * Some fixes and increase power of recording id * Fix NRE when no tags * Fix NRE when some (but not all) files in a directory have missing tags * Bump taglib, tidy up tag parsing * Add a health check * Remove media info setting * Tags -> audioTags * Add some tests where tags are null * Rename history events * Add missing method to interface * Reinstate MediaInfo tags and update info with artist scan Also adds migration to remove old format media info * This file no longer exists * Don't penalise year if missing from tags * Formatting improvements * Use correct system newline * Switch to the netstandard2.0 library to support net 461 * TagLib.File is IDisposable so should be in a using * Improve filename matching and add tests * Neater logging of parsed tags * Fix disk scan tests for new media info update * Fix quality detection source * Fix Inexact Artist/Album match * Add button to clear track mapping * Fix warning * Pacify eslint * Use \ not / * Fix UI updates * Fix media covers Prevent localizing URL propaging back to the metadata object * Reduce database overhead broadcasting UI updates * Relax timings a bit to make test pass * Remove irrelevant tests * Test framework for identification service * Fix PreferMissingToBadMatch test case * Make fingerprinting more robust * More logging * Penalize unknown media format and country * Prefer USA to UK * Allow Data CD * Fix exception if fingerprinting fails for all files * Fix tests * Fix NRE * Allow apostrophes and remove accents in filename aggregation * Address codacy issues * Cope with old versions of fpcalc and suggest upgrade * fpcalc health check passes if fingerprinting disabled * Get the Artist meta with the artist * Fix the mapper so that lazy loaded lists will be populated on Join And therefore we can join TrackFiles on Tracks by default and avoid an extra query * Rename subtitle -> lyric * Tidy up MediaInfoFormatter
5 years ago
[Test]
public void should_lazy_load_artist_for_track()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.ToList();
Assert.IsNotEmpty(tracks);
foreach (var track in tracks)
{
Assert.IsFalse(track.Artist.IsLoaded);
Assert.IsNotNull(track.Artist.Value);
Assert.IsTrue(track.Artist.IsLoaded);
Assert.IsTrue(track.Artist.Value.Metadata.IsLoaded);
}
}
[Test]
public void should_lazy_load_artist_for_trackfile()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<TrackFile>()
.ToList();
Assert.IsNotEmpty(tracks);
foreach (var track in tracks)
{
Assert.IsFalse(track.Artist.IsLoaded);
Assert.IsNotNull(track.Artist.Value);
Assert.IsTrue(track.Artist.IsLoaded);
Assert.IsTrue(track.Artist.Value.Metadata.IsLoaded);
}
}
[Test]
public void should_lazy_load_trackfile_if_not_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.ToList();
foreach (var track in tracks)
{
Assert.IsFalse(track.TrackFile.IsLoaded);
Assert.IsNotNull(track.TrackFile.Value);
Assert.IsTrue(track.TrackFile.IsLoaded);
}
}
[Test]
public void should_explicit_load_everything_if_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var files = DataMapper.Query<TrackFile>()
.Join<TrackFile, Track>(JoinType.Inner, f => f.Tracks, (f, t) => f.Id == t.TrackFileId)
.Join<TrackFile, Album>(JoinType.Inner, t => t.Album, (t, a) => t.AlbumId == a.Id)
.Join<TrackFile, Artist>(JoinType.Inner, t => t.Artist, (t, a) => t.Album.Value.ArtistMetadataId == a.ArtistMetadataId)
.Join<Artist, ArtistMetadata>(JoinType.Inner, a => a.Metadata, (a, m) => a.ArtistMetadataId == m.Id)
.ToList();
Assert.IsNotEmpty(files);
foreach (var file in files)
{
Assert.IsTrue(file.Tracks.IsLoaded);
Assert.IsNotEmpty(file.Tracks.Value);
Assert.IsTrue(file.Album.IsLoaded);
Assert.IsTrue(file.Artist.IsLoaded);
Assert.IsTrue(file.Artist.Value.Metadata.IsLoaded);
}
}
[Test]
public void should_lazy_load_tracks_if_not_joined_to_trackfile()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var files = DataMapper.Query<TrackFile>()
.Join<TrackFile, Album>(JoinType.Inner, t => t.Album, (t, a) => t.AlbumId == a.Id)
.Join<TrackFile, Artist>(JoinType.Inner, t => t.Artist, (t, a) => t.Album.Value.ArtistMetadataId == a.ArtistMetadataId)
.Join<Artist, ArtistMetadata>(JoinType.Inner, a => a.Metadata, (a, m) => a.ArtistMetadataId == m.Id)
.ToList();
Assert.IsNotEmpty(files);
foreach (var file in files)
{
Assert.IsFalse(file.Tracks.IsLoaded);
Assert.IsNotNull(file.Tracks.Value);
Assert.IsNotEmpty(file.Tracks.Value);
Assert.IsTrue(file.Tracks.IsLoaded);
Assert.IsTrue(file.Album.IsLoaded);
Assert.IsTrue(file.Artist.IsLoaded);
Assert.IsTrue(file.Artist.Value.Metadata.IsLoaded);
}
}
[Test]
public void should_lazy_load_tracks_if_not_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var release = DataMapper.Query<AlbumRelease>().Where(x => x.Id == 1).SingleOrDefault();
Assert.IsFalse(release.Tracks.IsLoaded);
Assert.IsNotNull(release.Tracks.Value);
Assert.IsNotEmpty(release.Tracks.Value);
Assert.IsTrue(release.Tracks.IsLoaded);
}
[Test]
public void should_lazy_load_track_if_not_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<TrackFile>()
.ToList();
foreach (var track in tracks)
{
Assert.IsFalse(track.Tracks.IsLoaded);
Assert.IsNotNull(track.Tracks.Value);
Assert.IsTrue(track.Tracks.IsLoaded);
}
}
[Test]
public void should_explicit_load_profile_if_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.Join<Track, AlbumRelease>(JoinType.Inner, v => v.AlbumRelease, (l, r) => l.AlbumReleaseId == r.Id)
.Join<AlbumRelease, Album>(JoinType.Inner, v => v.Album, (l, r) => l.AlbumId == r.Id)
.Join<Album, Artist>(JoinType.Inner, v => v.Artist, (l, r) => l.ArtistMetadataId == r.ArtistMetadataId)
.Join<Artist, Profile>(JoinType.Inner, v => v.Profile, (l, r) => l.ProfileId == r.Id)
.ToList();
foreach (var track in tracks)
{
Assert.IsTrue(track.AlbumRelease.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.Value.Artist.IsLoaded);
Assert.IsNotNull(track.AlbumRelease.Value.Album.Value.Artist.Value);
Assert.IsTrue(track.AlbumRelease.Value.Album.Value.Artist.Value.Profile.IsLoaded);
Assert.IsFalse(track.AlbumRelease.Value.Album.Value.Artist.Value.LanguageProfile.IsLoaded);
}
}
[Test]
public void should_explicit_load_languageprofile_if_joined()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var tracks = DataMapper.Query<Track>()
.Join<Track, AlbumRelease>(JoinType.Inner, v => v.AlbumRelease, (l, r) => l.AlbumReleaseId == r.Id)
.Join<AlbumRelease, Album>(JoinType.Inner, v => v.Album, (l, r) => l.AlbumId == r.Id)
.Join<Album, Artist>(JoinType.Inner, v => v.Artist, (l, r) => l.ArtistMetadataId == r.ArtistMetadataId)
.Join<Artist, LanguageProfile>(JoinType.Inner, v => v.LanguageProfile, (l, r) => l.LanguageProfileId == r.Id)
.ToList();
foreach (var track in tracks)
{
Assert.IsTrue(track.AlbumRelease.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.Value.Artist.IsLoaded);
Assert.IsNotNull(track.AlbumRelease.Value.Album.Value.Artist.Value);
Assert.IsFalse(track.AlbumRelease.Value.Album.Value.Artist.Value.Profile.IsLoaded);
Assert.IsTrue(track.AlbumRelease.Value.Album.Value.Artist.Value.LanguageProfile.IsLoaded);
}
}
}
}