1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 20:42:37 +01:00

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 @@ public void existing_episodes_only_calls_Update()
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 @@ public void existing_episodes_keep_their_episodeId_file_id()
.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 @@ public void EpisodesWithoutFiles_no_specials()
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 @@ 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();

View File

@ -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<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 @@ public virtual bool IsIgnored(int seriesId, int seasonNumber)
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 @@ 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)