Update episode info now uses UpdateMany, InsertMany

pull/6/head
kay.one 14 years ago
parent 2980c91f19
commit 9244a4e6ef

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

@ -241,17 +241,8 @@ namespace NzbDrone.Core.Providers
}
}
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 @@ namespace NzbDrone.Core.Providers
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)
{
@ -276,10 +267,10 @@ namespace NzbDrone.Core.Providers
return false;
//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);
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 @@ namespace NzbDrone.Core.Providers
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)

Loading…
Cancel
Save