From 90d9e7d41eb1a118c90631ffff30b0e1f6070d0d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 2 Jun 2011 20:04:39 -0700 Subject: [PATCH] Moved episodeCount logic to mediaFileProvider. Episode count counts by 5 now, so it doesn't take forever. --- NzbDrone.Core/Providers/MediaFileProvider.cs | 13 +++++++-- NzbDrone.Web/Controllers/SeriesController.cs | 17 ++++++------ NzbDrone.Web/NzbDrone.Web.csproj | 1 + NzbDrone.Web/Views/Series/Index.cshtml | 17 +++++++++++- NzbDrone.Web/Views/Settings/Test.cshtml | 29 ++++++++++++++------ 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 8f0532435..363e3029f 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -168,8 +168,6 @@ namespace NzbDrone.Core.Providers } } - - public virtual void Update(EpisodeFile episodeFile) { _repository.Update(episodeFile); @@ -195,6 +193,17 @@ namespace NzbDrone.Core.Providers return _seriesProvider.GetSeries(seriesId).Episodes.Where(c => c.EpisodeFile != null).Select(c => c.EpisodeFile); } + public virtual Tuple GetEpisodeFilesCount(int seriesId) + { + var series = _seriesProvider.GetSeries(seriesId); + + var monitoredSeasons = series.Seasons.Where(e => e.Monitored).Select(e => e.SeasonId); + var episodeTotal = series.Episodes.Where(e => monitoredSeasons.Contains(e.SeasonId) && e.AirDate <= DateTime.Today && e.AirDate > new DateTime(1899, 12, 31)); + var episodes = episodeTotal.Where(e => e.EpisodeFileId > 0); + + return new Tuple(episodeTotal.Count(), episodes.Count()); + } + private List GetMediaFileList(string path) { Logger.Debug("Scanning '{0}' for episodes", path); diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index fd2cbf141..0d162be05 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -21,6 +21,7 @@ namespace NzbDrone.Web.Controllers private readonly TvDbProvider _tvDbProvider; private readonly JobProvider _jobProvider; private readonly SeasonProvider _seasonProvider; + private readonly MediaFileProvider _mediaFileProvider; // // GET: /Series/ @@ -29,8 +30,9 @@ namespace NzbDrone.Web.Controllers QualityProvider qualityProvider, RenameProvider renameProvider, TvDbProvider tvDbProvider, - JobProvider jobProvider, - SeasonProvider seasonProvider) + JobProvider jobProvider, + SeasonProvider seasonProvider, + MediaFileProvider mediaFileProvider) { _seriesProvider = seriesProvider; _episodeProvider = episodeProvider; @@ -39,6 +41,7 @@ namespace NzbDrone.Web.Controllers _tvDbProvider = tvDbProvider; _jobProvider = jobProvider; _seasonProvider = seasonProvider; + _mediaFileProvider = mediaFileProvider; } public ActionResult Index() @@ -135,16 +138,12 @@ namespace NzbDrone.Web.Controllers public JsonResult GetEpisodeCount(int seriesId) { - var series = _seriesProvider.GetSeries(seriesId); - - var monitoredSeasons = series.Seasons.Where(e => e.Monitored).Select(e => e.SeasonId); - var episodeTotal = series.Episodes.Where(e => monitoredSeasons.Contains(e.SeasonId) && e.AirDate <= DateTime.Today && e.AirDate > new DateTime(1899, 12, 31)); - var episodes = episodeTotal.Where(e => e.EpisodeFileId > 0); + var count = _mediaFileProvider.GetEpisodeFilesCount(seriesId); return Json(new { - Episodes = episodes.Count(), - EpisodeTotal = episodeTotal.Count() + Episodes = count.Item1, + EpisodeTotal = count.Item2 }, JsonRequestBehavior.AllowGet); } diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index e3c66be01..4a515dd1e 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -673,6 +673,7 @@ + diff --git a/NzbDrone.Web/Views/Series/Index.cshtml b/NzbDrone.Web/Views/Series/Index.cshtml index 804c31879..cea5c4652 100644 --- a/NzbDrone.Web/Views/Series/Index.cshtml +++ b/NzbDrone.Web/Views/Series/Index.cshtml @@ -169,7 +169,22 @@ success: function (data, textStatus, jqXHR) { var episodes = data.Episodes; var episodeTotal = data.EpisodeTotal; - $("#progressbar_" + seriesId).episodeProgress(episodes, episodeTotal); + + var counter = 0; + var max = episodes + 1; + + $.doTimeout(10, function () { + if (counter >= max) { + $("#progressbar_" + seriesId).episodeProgress(episodes, episodeTotal); + return false; + } + + $("#progressbar_" + seriesId).episodeProgress(counter, episodeTotal); + + counter += 5; + + return true; + }); } }); } diff --git a/NzbDrone.Web/Views/Settings/Test.cshtml b/NzbDrone.Web/Views/Settings/Test.cshtml index b904ce326..9349f7ef8 100644 --- a/NzbDrone.Web/Views/Settings/Test.cshtml +++ b/NzbDrone.Web/Views/Settings/Test.cshtml @@ -102,24 +102,35 @@ +
+
+
+ +
+
+ \ No newline at end of file