No longer checking history when doing a manual search.

pull/3113/head
Mark McDowall 13 years ago
parent 926bdef527
commit d1262f1ced

@ -274,5 +274,38 @@ namespace NzbDrone.Core.Test.ProviderTests
Assert.AreEqual(excpected, result);
}
[Test]
public void IsQualityNeeded_file_should_skip_history_check_for_manual_search()
{
WithStrictMocker();
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
Mocker.GetMock<HistoryProvider>()
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns<Quality>(null);
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode });
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle, true);
//Assert
result.Should().BeTrue();
Mocker.Verify<HistoryProvider>(c => c.GetBestQualityInHistory(It.IsAny<int>()), Times.Never());
}
}
}

@ -75,14 +75,14 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
private void WithQualityNeeded()
{
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>()))
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true))
.Returns(true);
}
private void WithQualityNotNeeded()
{
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>()))
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true))
.Returns(false);
}
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
WithSuccessfulDownload();
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
.Setup(s => s.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p), true))
.Returns(true);
//Act
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert
result.Should().BeTrue();
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true),
Times.Once());
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Once());
@ -134,7 +134,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert
result.Should().BeFalse();
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true),
Times.Exactly(5));
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Never());

@ -75,14 +75,14 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
private void WithQualityNeeded()
{
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>()))
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true))
.Returns(true);
}
private void WithQualityNotNeeded()
{
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>()))
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true))
.Returns(false);
}
@ -102,7 +102,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
WithSuccessfulDownload();
Mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
.Setup(s => s.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p), true))
.Returns(true);
//Act
@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
result.Should().HaveCount(1);
result.First().Should().Be(1);
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true),
Times.Once());
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Once());
@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
//Assert
result.Should().HaveCount(0);
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>(), true),
Times.Exactly(5));
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Never());

@ -68,10 +68,11 @@ namespace NzbDrone.Core.Providers
/// Comprehensive check on whether or not this episode is needed.
/// </summary>
/// <param name = "parsedReport">Episode that needs to be checked</param>
/// <param name="manualSearch">False unless called by a manual search job</param>
/// <returns>Whether or not the file quality meets the requirements </returns>
/// <remarks>for multi episode files, all episodes need to meet the requirement
/// before the report is downloaded</remarks>
public virtual bool IsQualityNeeded(EpisodeParseResult parsedReport)
public virtual bool IsQualityNeeded(EpisodeParseResult parsedReport, bool manualSearch = false)
{
Logger.Trace("Checking if report meets quality requirements. {0}", parsedReport.Quality);
if (!parsedReport.Series.QualityProfile.Allowed.Contains(parsedReport.Quality.QualityType))
@ -96,13 +97,16 @@ namespace NzbDrone.Core.Providers
return false;
}
//Checking History
var bestQualityInHistory = _historyProvider.GetBestQualityInHistory(episode.EpisodeId);
if (bestQualityInHistory != null)
//Checking History (If not a manual search)
if (!manualSearch)
{
Logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
if (!IsUpgrade(bestQualityInHistory, parsedReport.Quality, cutoff))
return false;
var bestQualityInHistory = _historyProvider.GetBestQualityInHistory(episode.EpisodeId);
if(bestQualityInHistory != null)
{
Logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
if(!IsUpgrade(bestQualityInHistory, parsedReport.Quality, cutoff))
return false;
}
}
}

@ -235,7 +235,7 @@ namespace NzbDrone.Core.Providers
if (successes.Intersect(episodeParseResult.EpisodeNumbers).Count() > 0)
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
if (_inventoryProvider.IsQualityNeeded(episodeParseResult, true))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
try
@ -286,7 +286,7 @@ namespace NzbDrone.Core.Providers
if (!episodeParseResult.AirDate.HasValue || episodeParseResult.AirDate.Value.Date != airDate.Date)
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
if (_inventoryProvider.IsQualityNeeded(episodeParseResult, true))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
try

Loading…
Cancel
Save