mirror of
https://github.com/Radarr/Radarr
synced 2024-12-26 01:38:24 +00:00
GetBestQualityInHistory will be handled in memory now
This commit is contained in:
parent
aea80870d3
commit
30a24fd0b4
3 changed files with 5 additions and 85 deletions
|
@ -30,78 +30,5 @@ public void Trim_Items()
|
|||
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 @@ public void Trim()
|
|||
}
|
||||
|
||||
|
||||
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 @@ public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
|
|||
private readonly IHistoryRepository _historyRepository;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public HistoryService(IHistoryRepository historyRepository, Logger logger)
|
||||
{
|
||||
_historyRepository = historyRepository;
|
||||
|
@ -52,7 +51,7 @@ public virtual void Trim()
|
|||
|
||||
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 a new issue