1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Moved IsFirstOrLastEpisodeOfSeason logic to AcceptableSize specification so we can reuse the seasonsearchcriteria to reduce the number of database calls.

This commit is contained in:
Taloth Saldono 2014-05-03 00:04:58 +02:00
parent 0187df38ec
commit 7b607ce895
3 changed files with 32 additions and 28 deletions

View File

@ -48,7 +48,7 @@ public void Setup()
Series = series,
Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode() }
Episodes = new List<Episode> { new Episode() { Id = 2 } }
};
@ -59,13 +59,21 @@ public void Setup()
.Build();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
Mocker.GetMock<IEpisodeService>().Setup(
s => s.GetEpisodesBySeason(It.IsAny<int>(), It.IsAny<int>()))
.Returns(new List<Episode>() {
new Episode(), new Episode(), new Episode(), new Episode(), new Episode(),
new Episode(), new Episode(), new Episode(), new Episode() { Id = 2 }, new Episode() });
}
private void GivenLastEpisode()
{
Mocker.GetMock<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(true);
s => s.GetEpisodesBySeason(It.IsAny<int>(), It.IsAny<int>()))
.Returns(new List<Episode>() {
new Episode(), new Episode(), new Episode(), new Episode(), new Episode(),
new Episode(), new Episode(), new Episode(), new Episode(), new Episode() { Id = 2 } });
}
[TestCase(30, 50, false)]
@ -110,10 +118,6 @@ public void multi_episode(int runtime, int sizeInMegaBytes, bool expectedResult)
parseResultMulti.Series = series;
parseResultMulti.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
Subject.IsSatisfiedBy(parseResultMulti, null).Should().Be(expectedResult);
}
@ -129,10 +133,6 @@ public void multiset_episode(int runtime, int sizeInMegaBytes, bool expectedResu
parseResultMultiSet.Series = series;
parseResultMultiSet.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
Subject.IsSatisfiedBy(parseResultMultiSet, null).Should().Be(expectedResult);
}

View File

@ -4,6 +4,7 @@
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using System.Collections.Generic;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
@ -66,10 +67,27 @@ public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase sear
//Multiply maxSize by Series.Runtime
maxSize = maxSize * subject.Series.Runtime * subject.Episodes.Count;
//Check if there was only one episode parsed and it is the first
if (subject.Episodes.Count == 1 && _episodeService.IsFirstOrLastEpisodeOfSeason(subject.Episodes.First().Id))
if (subject.Episodes.Count == 1)
{
maxSize = maxSize * 2;
Episode episode = subject.Episodes.First();
List<Episode> seasonEpisodes;
var seasonSearchCriteria = searchCriteria as SeasonSearchCriteria;
if (seasonSearchCriteria != null && !seasonSearchCriteria.Series.UseSceneNumbering && seasonSearchCriteria.Episodes.Any(v => v.Id == episode.Id))
{
seasonEpisodes = (searchCriteria as SeasonSearchCriteria).Episodes;
}
else
{
seasonEpisodes = _episodeService.GetEpisodesBySeason(episode.SeriesId, episode.SeasonNumber);
}
//Ensure that this is either the first episode
//or is the last episode in a season that has 10 or more episodes
if (seasonEpisodes.First().Id == episode.Id || (seasonEpisodes.Count() >= 10 && seasonEpisodes.Last().Id == episode.Id))
{
maxSize = maxSize * 2;
}
}
//If the parsed size is greater than maxSize we don't want it

View File

@ -27,7 +27,6 @@ public interface IEpisodeService
List<Episode> GetEpisodesByFileId(int episodeFileId);
void UpdateEpisode(Episode episode);
void SetEpisodeMonitored(int episodeId, bool monitored);
bool IsFirstOrLastEpisodeOfSeason(int episodeId);
void UpdateEpisodes(List<Episode> episodes);
List<Episode> EpisodesBetweenDates(DateTime start, DateTime end);
void InsertMany(List<Episode> episodes);
@ -141,19 +140,6 @@ public void SetEpisodeMonitoredBySeason(int seriesId, int seasonNumber, bool mon
_episodeRepository.SetMonitoredBySeason(seriesId, seasonNumber, monitored);
}
public bool IsFirstOrLastEpisodeOfSeason(int episodeId)
{
var episode = GetEpisode(episodeId);
var seasonEpisodes = GetEpisodesBySeason(episode.SeriesId, episode.SeasonNumber);
//Ensure that this is either the first episode
//or is the last episode in a season that has 10 or more episodes
if (seasonEpisodes.First().EpisodeNumber == episode.EpisodeNumber || (seasonEpisodes.Count() >= 10 && seasonEpisodes.Last().EpisodeNumber == episode.EpisodeNumber))
return true;
return false;
}
public void UpdateEpisodes(List<Episode> episodes)
{
_episodeRepository.UpdateMany(episodes);