mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 04:22:30 +01:00
Removed AttachSeries for IEnumerable and using join instead, speed difference is negligible or in some cases faster .
This commit is contained in:
parent
8592ae4c88
commit
179de93a6e
@ -218,6 +218,10 @@ public void AttachSeries_single_invalid_series()
|
||||
[Test]
|
||||
public void GetEpisodesBySeason_success()
|
||||
{
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 12)
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.WhereAll().Have(c => c.SeriesId = 12)
|
||||
.WhereTheFirst(5).Have(c => c.SeasonNumber = 1)
|
||||
@ -227,7 +231,8 @@ public void GetEpisodesBySeason_success()
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
episodes.ToList().ForEach(c => db.Insert(c));
|
||||
db.Insert(fakeSeries);
|
||||
db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
var seasonEposodes = mocker.Resolve<EpisodeProvider>().GetEpisodesBySeason(12, 2);
|
||||
@ -257,7 +262,10 @@ public void RefreshEpisodeInfo_emptyRepo()
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
db.Insert(fakeSeries);
|
||||
|
||||
mocker.GetMock<TvDbProvider>()
|
||||
.Setup(c => c.GetSeries(seriesId, true))
|
||||
@ -292,10 +300,12 @@ public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
db.Insert(fakeSeries);
|
||||
|
||||
mocker.GetMock<TvDbProvider>()
|
||||
.Setup(c => c.GetSeries(seriesId, true))
|
||||
@ -335,7 +345,7 @@ public void new_episodes_only_calls_Insert()
|
||||
.Returns(tvdbSeries);
|
||||
|
||||
mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(currentEpisodes);
|
||||
|
||||
|
||||
@ -362,7 +372,7 @@ public void existing_episodes_only_calls_Update()
|
||||
var currentEpisodes = new List<Episode>();
|
||||
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
||||
{
|
||||
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id });
|
||||
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, Series = fakeSeries });
|
||||
}
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
@ -372,7 +382,7 @@ public void existing_episodes_only_calls_Update()
|
||||
.Returns(tvdbSeries);
|
||||
|
||||
mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(currentEpisodes);
|
||||
|
||||
//Act
|
||||
@ -397,12 +407,12 @@ public void should_try_to_get_existing_episode_using_tvdbid_first()
|
||||
)
|
||||
.Build();
|
||||
|
||||
var fakeEpisodeList = new List<Episode> { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10 } };
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
var fakeEpisodeList = new List<Episode> { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries} };
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(fakeEpisodeList);
|
||||
|
||||
mocker.GetMock<TvDbProvider>()
|
||||
@ -442,7 +452,6 @@ public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_ep
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
||||
@ -450,7 +459,7 @@ public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_ep
|
||||
.Returns(tvdbSeries);
|
||||
|
||||
mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(new List<Episode> { localEpisode });
|
||||
|
||||
//Act
|
||||
@ -474,7 +483,7 @@ public void existing_episodes_keep_their_episodeId_file_id()
|
||||
var currentEpisodes = new List<Episode>();
|
||||
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
||||
{
|
||||
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true });
|
||||
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries});
|
||||
}
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
@ -486,7 +495,7 @@ public void existing_episodes_keep_their_episodeId_file_id()
|
||||
var updatedEpisodes = new List<Episode>();
|
||||
|
||||
mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(currentEpisodes);
|
||||
|
||||
mocker.GetMock<IDatabase>()
|
||||
@ -1288,5 +1297,63 @@ public void EpisodesWithFiles_no_files()
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEpisodesByFileId_multi_episodes()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 10)
|
||||
.Build();
|
||||
|
||||
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.EpisodeFileId = 12345)
|
||||
.Build();
|
||||
|
||||
db.Insert(series);
|
||||
db.InsertMany(fakeEpisodes);
|
||||
|
||||
//Act
|
||||
var episodes = mocker.Resolve<EpisodeProvider>().GetEpisodesByFileId(12345);
|
||||
|
||||
//Assert
|
||||
episodes.Should().HaveCount(2);
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEpisodesByFileId_single_episode()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 10)
|
||||
.Build();
|
||||
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.SeriesId = 10)
|
||||
.With(c => c.SeasonNumber = 1)
|
||||
.With(c => c.EpisodeFileId = 12345)
|
||||
.Build();
|
||||
|
||||
db.Insert(series);
|
||||
db.Insert(fakeEpisode);
|
||||
|
||||
//Act
|
||||
var episodes = mocker.Resolve<EpisodeProvider>().GetEpisodesByFileId(12345);
|
||||
|
||||
//Assert
|
||||
episodes.Should().HaveCount(1);
|
||||
episodes.First().ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisode);
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
}
|
||||
}
|
@ -84,9 +84,10 @@ public virtual Episode GetEpisode(int seriesId, DateTime date)
|
||||
|
||||
public virtual IList<Episode> GetEpisodeBySeries(long seriesId)
|
||||
{
|
||||
var episodes = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
|
||||
var episodes = _database.Fetch<Episode, Series, EpisodeFile>(@"SELECT * FROM Episodes
|
||||
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
||||
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
|
||||
WHERE Episodes.SeriesId = @0", seriesId));
|
||||
WHERE Episodes.SeriesId = @0", seriesId);
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
@ -99,9 +100,10 @@ public virtual IList<Episode> GetEpisodeBySeries(long seriesId)
|
||||
|
||||
public virtual IList<Episode> GetEpisodesBySeason(long seriesId, int seasonNumber)
|
||||
{
|
||||
var episodes = AttachSeries(_database.Fetch<Episode, EpisodeFile>(@"SELECT * FROM Episodes
|
||||
var episodes = _database.Fetch<Episode, Series, EpisodeFile>(@"SELECT * FROM Episodes
|
||||
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
||||
LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId
|
||||
WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1", seriesId, seasonNumber));
|
||||
WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1", seriesId, seasonNumber);
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
@ -175,7 +177,9 @@ INNER JOIN Series
|
||||
|
||||
public virtual IList<Episode> GetEpisodesByFileId(int episodeFileId)
|
||||
{
|
||||
return AttachSeries(_database.Fetch<Episode>("WHERE EpisodeFileId = @0", episodeFileId));
|
||||
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
||||
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
||||
WHERE EpisodeFileId = @0", episodeFileId);
|
||||
}
|
||||
|
||||
public virtual IList<Episode> EpisodesWithFiles()
|
||||
|
Loading…
Reference in New Issue
Block a user