From ddb25b109575cc378462a1c3a64705f2003f01f0 Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Sun, 12 Feb 2023 16:34:04 -0600 Subject: [PATCH] New: Use better page size for Newznab/Torznab (up to 100) when supported by the indexer Closes #5373 --- .../IndexerTests/NewznabTests/NewznabFixture.cs | 13 +++++++++++-- .../IndexerTests/TorznabTests/TorznabFixture.cs | 13 +++++++++++-- src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 2 +- src/NzbDrone.Core/Indexers/Torznab/Torznab.cs | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs index 31d9f06d4..7840e4253 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs @@ -94,12 +94,21 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests } [Test] - public void should_use_pagesize_reported_by_caps() + public void should_use_best_pagesize_reported_by_caps() { _caps.MaxPageSize = 30; _caps.DefaultPageSize = 25; - Subject.PageSize.Should().Be(25); + Subject.PageSize.Should().Be(30); + } + + [Test] + public void should_not_use_pagesize_over_100_even_if_reported_in_caps() + { + _caps.MaxPageSize = 250; + _caps.DefaultPageSize = 25; + + Subject.PageSize.Should().Be(100); } [Test] diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs index cbe0b1d3f..63f47cf5e 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs @@ -136,12 +136,21 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests } [Test] - public void should_use_pagesize_reported_by_caps() + public void should_use_best_pagesize_reported_by_caps() { _caps.MaxPageSize = 30; _caps.DefaultPageSize = 25; - Subject.PageSize.Should().Be(25); + Subject.PageSize.Should().Be(30); + } + + [Test] + public void should_not_use_pagesize_over_100_even_if_reported_in_caps() + { + _caps.MaxPageSize = 250; + _caps.DefaultPageSize = 25; + + Subject.PageSize.Should().Be(100); } [TestCase("http://localhost:9117/", "/api")] diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 6aa2fc89c..3043a042a 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.Newznab public override DownloadProtocol Protocol => DownloadProtocol.Usenet; - public override int PageSize => _capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize; + public override int PageSize => Math.Min(100, Math.Max(_capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize, _capabilitiesProvider.GetCapabilities(Settings).MaxPageSize)); public override IIndexerRequestGenerator GetRequestGenerator() { diff --git a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs index 5741ba3f7..40bde50a0 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers.Torznab public override string Name => "Torznab"; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; - public override int PageSize => _capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize; + public override int PageSize => Math.Min(100, Math.Max(_capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize, _capabilitiesProvider.GetCapabilities(Settings).MaxPageSize)); public override IIndexerRequestGenerator GetRequestGenerator() {