GetEpisodeFilesCount should be around 5 times faster.

This commit is contained in:
kay.one 2011-06-05 00:25:50 -07:00
parent 72af060d68
commit 54d1d5e379
5 changed files with 58 additions and 15 deletions

View File

@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert
var actualCount = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId).Count;
var actualCount = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId).ToList().Count;
mocker.GetMock<TvDbProvider>().VerifyAll();
actualCount.Should().Be(episodeCount);
mocker.VerifyAllMocks();

View File

@ -29,6 +29,7 @@ namespace NzbDrone.Core.Test
base.Setup();
int currentFileId = 0;
foreach (var _seriesId in seriesIds)
{
@ -44,27 +45,38 @@ namespace NzbDrone.Core.Test
{
for (int i = 1; i <= Episodes_Per_Season; i++)
{
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = seriesId)
.And(e => e.SeasonNumber = _seasonNumber)
.And(e => e.EpisodeNumber = i)
.And(e => e.Ignored = false)
.And(e => e.TvDbEpisodeId = episodes.Count + 1)
.And(e => e.AirDate = DateTime.Today.AddDays(-20))
.Build();
episodes.Add(episode);
var epFileId = 0;
if (i < 10)
{
var epFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.SeriesId = seriesId)
.With(e => e.SeriesId = seriesId)
.And(e => e.SeasonNumber = _seasonNumber)
.And(e => e.Path = Guid.NewGuid().ToString())
.Build();
files.Add(epFile);
currentFileId++;
epFileId = currentFileId;
}
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = seriesId)
.And(e => e.SeasonNumber = _seasonNumber)
.And(e => e.EpisodeNumber = i)
.And(e => e.Ignored = false)
.And(e => e.TvDbEpisodeId = episodes.Count + 1)
.And(e => e.EpisodeFileId = epFileId)
.And(e => e.AirDate = DateTime.Today.AddDays(-20))
.Build();
episodes.Add(episode);
}
}
@ -72,8 +84,7 @@ namespace NzbDrone.Core.Test
repo.AddMany(episodes);
repo.AddMany(files);
}
}
[Test]
@ -177,5 +188,36 @@ namespace NzbDrone.Core.Test
Console.WriteLine("Took " + sw.Elapsed);
}
[Test]
public void get_episode_file_count_x10()
{
var mocker = new AutoMoq.AutoMoqer();
mocker.SetConstant(repo);
mocker.SetConstant(mocker.Resolve<EpisodeProvider>());
var provider = mocker.Resolve<MediaFileProvider>();
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
{
var result = provider.GetEpisodeFilesCount(random.Next(1, 10));
result.Item1.Should().NotBe(0);
result.Item2.Should().NotBe(0);
}
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
}
}
}

View File

@ -191,10 +191,10 @@ namespace NzbDrone.Core.Providers
{
var allEpisodes = _episodeProvider.GetEpisodeBySeries(seriesId);
var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate <= DateTime.Today && e.AirDate.Year > 1900).ToList();
var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate <= DateTime.Today && e.AirDate.Year > 1900);
var avilableEpisodes = episodeTotal.Where(e => e.EpisodeFileId > 0);
return new Tuple<int, int>(avilableEpisodes.Count(), episodeTotal.Count);
return new Tuple<int, int>(avilableEpisodes.Count(), episodeTotal.Count());
}
private List<string> GetMediaFileList(string path)

View File

@ -11,6 +11,7 @@
<add key="UnobtrusiveJavaScriptEnabled" value="false" />
</appSettings>
<system.web>
<trust level="Full" originUrl=".*" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />