mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 07:22:35 +01:00
GetBestQualityInHistory will be handled in memory now
This commit is contained in:
parent
aea80870d3
commit
30a24fd0b4
@ -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<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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace NzbDrone.Core.History
|
||||
public interface IHistoryRepository : IBasicRepository<History>
|
||||
{
|
||||
void Trim();
|
||||
QualityModel GetBestQualityInHistory(int episodeId);
|
||||
List<QualityModel> GetBestQualityInHistory(int episodeId);
|
||||
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
|
||||
}
|
||||
|
||||
@ -30,17 +30,11 @@ namespace NzbDrone.Core.History
|
||||
}
|
||||
|
||||
|
||||
public QualityModel GetBestQualityInHistory(int episodeId)
|
||||
public List<QualityModel> 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<History> Paged(PagingSpec<History> pagingSpec)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user