From 9244a4e6ef8aed3cd22c1b4d00479b9f0a771860 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 28 Aug 2011 20:03:40 -0700 Subject: [PATCH] Update episode info now uses UpdateMany, InsertMany --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 13 ++++++------- NzbDrone.Core/Providers/EpisodeProvider.cs | 21 ++++++--------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index a4f078c5f..f7c5323eb 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -388,8 +388,8 @@ public void existing_episodes_only_calls_Update() mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - mocker.GetMock().Verify(c => c.Insert(It.IsAny()), Times.Never()); - mocker.GetMock().Verify(c => c.Update(It.IsAny()), Times.Exactly(tvdbSeries.Episodes.Count)); + mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 0)), Times.Once()); + mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(l => l.Count() == 5)), Times.Once()); mocker.VerifyAllMocks(); } @@ -499,9 +499,8 @@ public void existing_episodes_keep_their_episodeId_file_id() .Returns(currentEpisodes); mocker.GetMock() - .Setup(c => c.Update(It.IsAny())) - .Returns(1) - .Callback(ep => updatedEpisodes.Add(ep)); + .Setup(c => c.UpdateMany(It.IsAny>())) + .Callback>(ep => updatedEpisodes =ep.ToList()); //Act mocker.Resolve().RefreshEpisodeInfo(fakeSeries); @@ -1175,7 +1174,7 @@ public void EpisodesWithoutFiles_no_specials() db.InsertMany(specials); //Act - var missingFiles= mocker.Resolve().EpisodesWithoutFiles(false); + var missingFiles = mocker.Resolve().EpisodesWithoutFiles(false); //Assert missingFiles.Should().HaveCount(1); @@ -1203,7 +1202,7 @@ public void EpisodesWithoutFiles_with_specials() .Have(c => c.Ignored = true) .WhereTheFirst(2) .Have(c => c.EpisodeFileId = 0) - .WhereSection(1,2) + .WhereSection(1, 2) .Have(c => c.Ignored = false) .Build().ToList(); diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 6961b2843..681d5e404 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -241,17 +241,8 @@ public virtual void RefreshEpisodeInfo(Series series) } } - using (var tran = _database.GetTransaction()) - { - newList.ForEach(AddEpisode); - updateList.ForEach(episode => _database.Update(episode)); - - //Shouldn't run if Database is a mock since transaction will be null - if (_database.GetType().Namespace != "Castle.Proxies" && tran != null) - { - tran.Complete(); - } - } + _database.InsertMany(newList); + _database.UpdateMany(updateList); Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", tvDbSeriesInfo.SeriesName, successCount, failCount); @@ -264,7 +255,7 @@ public virtual void UpdateEpisode(Episode episode) public virtual bool IsIgnored(int seriesId, int seasonNumber) { - var episodes =_database.Fetch(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber); + var episodes = _database.Fetch(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber); if (episodes == null || episodes.Count == 0) { @@ -276,10 +267,10 @@ public virtual bool IsIgnored(int seriesId, int seasonNumber) return false; //else - var lastSeasonsEpisodes =_database.Fetch(@"SELECT * FROM Episodes + var lastSeasonsEpisodes = _database.Fetch(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber - 1); - if (lastSeasonsEpisodes !=null && lastSeasonsEpisodes.Count > 0 && lastSeasonsEpisodes.Count == lastSeasonsEpisodes.Where(e => e.Ignored).Count()) + if (lastSeasonsEpisodes != null && lastSeasonsEpisodes.Count > 0 && lastSeasonsEpisodes.Count == lastSeasonsEpisodes.Where(e => e.Ignored).Count()) return true; return false; @@ -309,7 +300,7 @@ public virtual void SetSeasonIgnore(long seriesId, int seasonNumber, bool isIgno WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3", isIgnored, seriesId, seasonNumber, !isIgnored); - Logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); + Logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); } public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored)