1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 02:09:59 +00:00

GetBestQualityInHistory will be handled in memory now

This commit is contained in:
Mark McDowall 2013-05-13 22:40:06 -07:00
parent aea80870d3
commit 30a24fd0b4
3 changed files with 5 additions and 85 deletions

View file

@ -30,78 +30,5 @@ public void Trim_Items()
AllStoredModels.Should().HaveCount(10); AllStoredModels.Should().HaveCount(10);
AllStoredModels.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30)); 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<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = series)
.With(c => c.SeriesId = series.Id)
.Build();
var history = Builder<History.History>.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<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = series)
.With(c => c.SeriesId = series.Id)
.Build();
var history = Builder<History.History>
.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();
}
} }
} }

View file

@ -12,7 +12,7 @@ namespace NzbDrone.Core.History
public interface IHistoryRepository : IBasicRepository<History> public interface IHistoryRepository : IBasicRepository<History>
{ {
void Trim(); void Trim();
QualityModel GetBestQualityInHistory(int episodeId); List<QualityModel> GetBestQualityInHistory(int episodeId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec); PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
} }
@ -30,17 +30,11 @@ public void Trim()
} }
public QualityModel GetBestQualityInHistory(int episodeId) public List<QualityModel> GetBestQualityInHistory(int episodeId)
{ {
var history = Query.Where(c => c.EpisodeId == episodeId) var history = Query.Where(c => c.EpisodeId == episodeId);
.OrderByDescending(c => c.Quality).FirstOrDefault();
if (history != null) return history.Select(h => h.Quality).ToList();
{
return history.Quality;
}
return null;
} }
public PagingSpec<History> Paged(PagingSpec<History> pagingSpec) public PagingSpec<History> Paged(PagingSpec<History> pagingSpec)

View file

@ -23,7 +23,6 @@ public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
private readonly IHistoryRepository _historyRepository; private readonly IHistoryRepository _historyRepository;
private readonly Logger _logger; private readonly Logger _logger;
public HistoryService(IHistoryRepository historyRepository, Logger logger) public HistoryService(IHistoryRepository historyRepository, Logger logger)
{ {
_historyRepository = historyRepository; _historyRepository = historyRepository;
@ -52,7 +51,7 @@ public virtual void Trim()
public virtual QualityModel GetBestQualityInHistory(int episodeId) public virtual QualityModel GetBestQualityInHistory(int episodeId)
{ {
return _historyRepository.GetBestQualityInHistory(episodeId); return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault();
} }
public void Handle(EpisodeGrabbedEvent message) public void Handle(EpisodeGrabbedEvent message)