Update episode info now uses UpdateMany, InsertMany

This commit is contained in:
kay.one 2011-08-28 20:03:40 -07:00
parent 2980c91f19
commit 9244a4e6ef
2 changed files with 12 additions and 22 deletions

View File

@ -388,8 +388,8 @@ namespace NzbDrone.Core.Test
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries); mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert //Assert
mocker.GetMock<IDatabase>().Verify(c => c.Insert(It.IsAny<Object>()), Times.Never()); mocker.GetMock<IDatabase>().Verify(c => c.InsertMany(It.Is<IEnumerable<Episode>>(l => l.Count() == 0)), Times.Once());
mocker.GetMock<IDatabase>().Verify(c => c.Update(It.IsAny<Object>()), Times.Exactly(tvdbSeries.Episodes.Count)); mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(It.Is<IEnumerable<Episode>>(l => l.Count() == 5)), Times.Once());
mocker.VerifyAllMocks(); mocker.VerifyAllMocks();
} }
@ -499,9 +499,8 @@ namespace NzbDrone.Core.Test
.Returns(currentEpisodes); .Returns(currentEpisodes);
mocker.GetMock<IDatabase>() mocker.GetMock<IDatabase>()
.Setup(c => c.Update(It.IsAny<Episode>())) .Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
.Returns(1) .Callback<IEnumerable<Episode>>(ep => updatedEpisodes =ep.ToList());
.Callback<Episode>(ep => updatedEpisodes.Add(ep));
//Act //Act
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries); mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
@ -1175,7 +1174,7 @@ namespace NzbDrone.Core.Test
db.InsertMany(specials); db.InsertMany(specials);
//Act //Act
var missingFiles= mocker.Resolve<EpisodeProvider>().EpisodesWithoutFiles(false); var missingFiles = mocker.Resolve<EpisodeProvider>().EpisodesWithoutFiles(false);
//Assert //Assert
missingFiles.Should().HaveCount(1); missingFiles.Should().HaveCount(1);
@ -1203,7 +1202,7 @@ namespace NzbDrone.Core.Test
.Have(c => c.Ignored = true) .Have(c => c.Ignored = true)
.WhereTheFirst(2) .WhereTheFirst(2)
.Have(c => c.EpisodeFileId = 0) .Have(c => c.EpisodeFileId = 0)
.WhereSection(1,2) .WhereSection(1, 2)
.Have(c => c.Ignored = false) .Have(c => c.Ignored = false)
.Build().ToList(); .Build().ToList();

View File

@ -241,17 +241,8 @@ namespace NzbDrone.Core.Providers
} }
} }
using (var tran = _database.GetTransaction()) _database.InsertMany(newList);
{ _database.UpdateMany(updateList);
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();
}
}
Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ",
tvDbSeriesInfo.SeriesName, successCount, failCount); tvDbSeriesInfo.SeriesName, successCount, failCount);
@ -264,7 +255,7 @@ namespace NzbDrone.Core.Providers
public virtual bool IsIgnored(int seriesId, int seasonNumber) public virtual bool IsIgnored(int seriesId, int seasonNumber)
{ {
var episodes =_database.Fetch<Episode>(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber); var episodes = _database.Fetch<Episode>(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber);
if (episodes == null || episodes.Count == 0) if (episodes == null || episodes.Count == 0)
{ {
@ -276,10 +267,10 @@ namespace NzbDrone.Core.Providers
return false; return false;
//else //else
var lastSeasonsEpisodes =_database.Fetch<Episode>(@"SELECT * FROM Episodes var lastSeasonsEpisodes = _database.Fetch<Episode>(@"SELECT * FROM Episodes
WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber - 1); 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 true;
return false; return false;
@ -309,7 +300,7 @@ namespace NzbDrone.Core.Providers
WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3", WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3",
isIgnored, seriesId, seasonNumber, !isIgnored); 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) public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored)