From 30a24fd0b47fdfce6fa04c02299f109d93e04610 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 13 May 2013 22:40:06 -0700 Subject: [PATCH] GetBestQualityInHistory will be handled in memory now --- .../HistoryTests/HistoryRepositoryFixture.cs | 73 ------------------- NzbDrone.Core/History/HistoryRepository.cs | 14 +--- NzbDrone.Core/History/HistoryService.cs | 3 +- 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs b/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs index b10f1cf4f..b71d2d066 100644 --- a/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs +++ b/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs @@ -30,78 +30,5 @@ namespace NzbDrone.Core.Test.HistoryTests AllStoredModels.Should().HaveCount(10); AllStoredModels.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30)); } - - - [Test] - public void GetBestQualityInHistory_no_result() - { - Subject.GetBestQualityInHistory(12).Should().Be(null); - } - - [Test] - public void GetBestQualityInHistory_single_result() - { - var series = Builder.CreateNew().Build(); - var episode = Builder.CreateNew() - .With(c => c.Series = series) - .With(c => c.SeriesId = series.Id) - .Build(); - - - - var history = Builder.CreateNew() - .With(c => c.Id = 0) - .With(h => h.Quality = new QualityModel(Quality.Bluray720p, true)) - .With(h => h.EpisodeId = episode.Id) - .Build(); - - Db.Insert(history); - - var result = Subject.GetBestQualityInHistory(episode.Id); - - result.Should().NotBeNull(); - result.Quality.Should().Be(Quality.Bluray720p); - result.Proper.Should().BeTrue(); - } - - [Test] - public void GetBestQualityInHistory_should_return_highest_result() - { - - var series = Builder.CreateNew().Build(); - var episode = Builder.CreateNew() - .With(c => c.Series = series) - .With(c => c.SeriesId = series.Id) - .Build(); - - - var history = Builder - .CreateListOfSize(5) - .All() - .With(c => c.Id = 0) - .With(h => h.EpisodeId = episode.Id) - .TheFirst(1) - .With(h => h.Quality = new QualityModel(Quality.DVD, true)) - .TheNext(1) - .With(h => h.Quality = new QualityModel(Quality.Bluray720p, true)) - .TheNext(1) - .With(h => h.Quality = new QualityModel(Quality.Bluray720p, true)) - .TheNext(1) - .With(h => h.Quality = new QualityModel(Quality.Bluray720p, false)) - .TheNext(1) - .With(h => h.Quality = new QualityModel(Quality.SDTV, true)) - .Build(); - - Db.InsertMany(history); - - var result = Subject.GetBestQualityInHistory(episode.Id); - - result.Should().NotBeNull(); - result.Quality.Should().Be(Quality.Bluray720p); - result.Proper.Should().BeTrue(); - } - - - } } \ No newline at end of file diff --git a/NzbDrone.Core/History/HistoryRepository.cs b/NzbDrone.Core/History/HistoryRepository.cs index 0068c1bb7..ae12bc7a4 100644 --- a/NzbDrone.Core/History/HistoryRepository.cs +++ b/NzbDrone.Core/History/HistoryRepository.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.History public interface IHistoryRepository : IBasicRepository { void Trim(); - QualityModel GetBestQualityInHistory(int episodeId); + List GetBestQualityInHistory(int episodeId); PagingSpec Paged(PagingSpec pagingSpec); } @@ -30,17 +30,11 @@ namespace NzbDrone.Core.History } - public QualityModel GetBestQualityInHistory(int episodeId) + public List GetBestQualityInHistory(int episodeId) { - var history = Query.Where(c => c.EpisodeId == episodeId) - .OrderByDescending(c => c.Quality).FirstOrDefault(); + var history = Query.Where(c => c.EpisodeId == episodeId); - if (history != null) - { - return history.Quality; - } - - return null; + return history.Select(h => h.Quality).ToList(); } public PagingSpec Paged(PagingSpec pagingSpec) diff --git a/NzbDrone.Core/History/HistoryService.cs b/NzbDrone.Core/History/HistoryService.cs index b65a0704c..708a21810 100644 --- a/NzbDrone.Core/History/HistoryService.cs +++ b/NzbDrone.Core/History/HistoryService.cs @@ -23,7 +23,6 @@ namespace NzbDrone.Core.History private readonly IHistoryRepository _historyRepository; private readonly Logger _logger; - public HistoryService(IHistoryRepository historyRepository, Logger logger) { _historyRepository = historyRepository; @@ -52,7 +51,7 @@ namespace NzbDrone.Core.History public virtual QualityModel GetBestQualityInHistory(int episodeId) { - return _historyRepository.GetBestQualityInHistory(episodeId); + return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault(); } public void Handle(EpisodeGrabbedEvent message)