From ff926d71f733a23a2e6c1a7bd4ca257b14cce848 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 27 Dec 2020 22:51:38 -0500 Subject: [PATCH] More accurate indexer query times in History --- .../FileListTests/FileListFixture.cs | 2 +- .../IndexerTests/HDBitsTests/HDBitsFixture.cs | 4 +- .../IPTorrentsTests/IPTorrentsFixture.cs | 2 +- .../NewznabTests/NewznabFixture.cs | 2 +- .../IndexerTests/NyaaTests/NyaaFixture.cs | 2 +- .../IndexerTests/PTPTests/PTPFixture.cs | 2 +- .../IndexerTests/RarbgTests/RarbgFixture.cs | 6 +- .../TorrentRssIndexerFixture.cs | 22 +++---- .../TorznabTests/TorznabFixture.cs | 6 +- src/NzbDrone.Core/History/HistoryService.cs | 1 + .../IndexerSearch/NzbSearchService.cs | 14 ++--- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 57 ++++++++++++------- src/NzbDrone.Core/Indexers/IIndexer.cs | 10 ++-- src/NzbDrone.Core/Indexers/IndexerBase.cs | 10 ++-- .../Indexers/IndexerPageableQueryResult.cs | 21 +++++++ .../Indexers/IndexerQueryResult.cs | 18 ++++++ src/NzbDrone.Core/Indexers/IndexerResponse.cs | 6 +- 17 files changed, 122 insertions(+), 63 deletions(-) create mode 100644 src/NzbDrone.Core/Indexers/IndexerPageableQueryResult.cs create mode 100644 src/NzbDrone.Core/Indexers/IndexerQueryResult.cs diff --git a/src/NzbDrone.Core.Test/IndexerTests/FileListTests/FileListFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/FileListTests/FileListFixture.cs index b0d3a3176..ca0e0f182 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/FileListTests/FileListFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/FileListTests/FileListFixture.cs @@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.IndexerTests.FileListTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(4); releases.First().Should().BeOfType(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs index 7b865c6c2..9fc936814 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs @@ -46,7 +46,7 @@ namespace NzbDrone.Core.Test.IndexerTests.HDBitsTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.POST))) .Returns(r => new HttpResponse(r, new HttpHeader(), responseJson)); - var torrents = Subject.Fetch(_movieSearchCriteria); + var torrents = Subject.Fetch(_movieSearchCriteria).Releases; torrents.Should().HaveCount(2); torrents.First().Should().BeOfType(); @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.IndexerTests.HDBitsTests .Setup(v => v.Execute(It.IsAny())) .Returns(r => new HttpResponse(r, new HttpHeader(), Encoding.UTF8.GetBytes(responseJson))); - var torrents = Subject.Fetch(_movieSearchCriteria); + var torrents = Subject.Fetch(_movieSearchCriteria).Releases; torrents.Should().BeEmpty(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/IPTorrentsTests/IPTorrentsFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/IPTorrentsTests/IPTorrentsFixture.cs index 3bd362ba6..fbd9afbda 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/IPTorrentsTests/IPTorrentsFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/IPTorrentsTests/IPTorrentsFixture.cs @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.IndexerTests.IPTorrentsTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(5); releases.First().Should().BeOfType(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs index 3ea4e843e..bb9f2145b 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 }, Limit = 100, Offset = 0 }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 }, Limit = 100, Offset = 0 }).Releases; releases.Should().HaveCount(100); diff --git a/src/NzbDrone.Core.Test/IndexerTests/NyaaTests/NyaaFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NyaaTests/NyaaFixture.cs index ee777fc9b..fabb4c292 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NyaaTests/NyaaFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NyaaTests/NyaaFixture.cs @@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NyaaTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria()); + var releases = Subject.Fetch(new MovieSearchCriteria()).Releases; releases.Should().HaveCount(4); releases.First().Should().BeOfType(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs index 3e5345e7f..f60a5bf2f 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.IndexerTests.PTPTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader { ContentType = HttpAccept.Json.Value }, responseJson)); - var torrents = Subject.Fetch(new MovieSearchCriteria()); + var torrents = Subject.Fetch(new MovieSearchCriteria()).Releases; torrents.Should().HaveCount(293); torrents.First().Should().BeOfType(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs index 5b00fe62f..3bcd81ae9 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Test.IndexerTests.RarbgTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(4); releases.First().Should().BeOfType(); @@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.IndexerTests.RarbgTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), "{ error_code: 20, error: \"some message\" }")); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(0); } @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.IndexerTests.RarbgTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), "{ error_code: 25, error: \"some message\" }")); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(0); diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs index cecd1fcfc..e4baf3756 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/ImmortalSeed.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(50); releases.First().Should().BeOfType(); @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/Ezrss.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(3); releases.First().Should().BeOfType(); @@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests GivenRecentFeedResponse("TorrentRss/ShowRSS.info.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(5); releases.First().Should().BeOfType(); @@ -127,7 +127,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests GivenRecentFeedResponse("TorrentRss/Doki.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(5); releases.First().Should().BeOfType(); @@ -153,7 +153,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/ExtraTorrents.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(5); releases.First().Should().BeOfType(); @@ -179,7 +179,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/LimeTorrents.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(5); releases.First().Should().BeOfType(); @@ -205,7 +205,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/AnimeTosho_NoSize.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(2); releases.First().Should().BeOfType(); @@ -231,7 +231,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/AnimeTosho_NoSize.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(2); releases.Last().Should().BeOfType(); @@ -248,7 +248,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/AlphaRatio.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(2); releases.Last().Should().BeOfType(); @@ -266,7 +266,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests Subject.Definition.Settings.As().AllowZeroSize = true; GivenRecentFeedResponse("TorrentRss/EvolutionWorld.xml"); - var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }); + var releases = Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases; releases.Should().HaveCount(2); releases.First().Should().BeOfType(); @@ -292,7 +292,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests { GivenRecentFeedResponse("TorrentRss/invalid/TorrentDay_NoPubDate.xml"); - Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Should().BeEmpty(); + Subject.Fetch(new MovieSearchCriteria { Categories = new int[] { 2000 } }).Releases.Should().BeEmpty(); Mocker.GetMock() .Verify(v => v.RecordFailure(It.IsAny(), TimeSpan.Zero), Times.Once()); diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs index a6e1ec1cb..7c3747b93 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria()); + var releases = Subject.Fetch(new MovieSearchCriteria()).Releases; releases.Should().HaveCount(5); @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria()); + var releases = Subject.Fetch(new MovieSearchCriteria()).Releases; releases.Should().HaveCount(5); @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); - var releases = Subject.Fetch(new MovieSearchCriteria()); + var releases = Subject.Fetch(new MovieSearchCriteria()).Releases; releases.Should().HaveCount(2); diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index bc568def9..5de72f740 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -91,6 +91,7 @@ namespace NzbDrone.Core.History history.Data.Add("ElapsedTime", message.Time.ToString()); history.Data.Add("Query", message.Query.SearchTerm ?? string.Empty); + history.Data.Add("Categories", string.Join(',', message.Query.Categories) ?? string.Empty); history.Data.Add("Successful", message.Successful.ToString()); history.Data.Add("QueryResults", message.Results.HasValue ? message.Results.ToString() : null); diff --git a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index c70a52817..229e3ba61 100644 --- a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -127,7 +127,7 @@ namespace NzbDrone.Core.IndexerSearch return spec; } - private List Dispatch(Func> searchAction, SearchCriteriaBase criteriaBase) + private List Dispatch(Func searchAction, SearchCriteriaBase criteriaBase) { var indexers = criteriaBase.InteractiveSearch ? _indexerFactory.InteractiveSearchEnabled() : @@ -151,25 +151,25 @@ namespace NzbDrone.Core.IndexerSearch taskList.Add(taskFactory.StartNew(() => { - var sw = Stopwatch.StartNew(); try { var indexerReports = searchAction(indexerLocal); lock (reports) { - reports.AddRange(indexerReports); + reports.AddRange(indexerReports.Releases); } - _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, sw.ElapsedMilliseconds, true, indexerReports.Count())); + foreach (var query in indexerReports.Queries) + { + _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, query.ElapsedTime, true, indexerReports.Releases.Count())); + } } catch (Exception e) { - _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, sw.ElapsedMilliseconds, false)); + _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, 0, false)); _logger.Error(e, "Error while searching for {0}", criteriaBase); } - - sw.Stop(); }).LogExceptions()); } diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 1f35faf7e..1d6ffc30e 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net; using FluentValidation.Results; @@ -40,7 +41,7 @@ namespace NzbDrone.Core.Indexers _httpClient = httpClient; } - public override IList Fetch(MovieSearchCriteria searchCriteria) + public override IndexerPageableQueryResult Fetch(MovieSearchCriteria searchCriteria) { //if (!SupportsSearch) //{ @@ -49,41 +50,41 @@ namespace NzbDrone.Core.Indexers return FetchReleases(g => g.GetSearchRequests(searchCriteria)); } - public override IList Fetch(MusicSearchCriteria searchCriteria) + public override IndexerPageableQueryResult Fetch(MusicSearchCriteria searchCriteria) { if (!SupportsSearch) { - return new List(); + return new IndexerPageableQueryResult(); } return FetchReleases(g => g.GetSearchRequests(searchCriteria)); } - public override IList Fetch(TvSearchCriteria searchCriteria) + public override IndexerPageableQueryResult Fetch(TvSearchCriteria searchCriteria) { if (!SupportsSearch) { - return new List(); + return new IndexerPageableQueryResult(); } return FetchReleases(g => g.GetSearchRequests(searchCriteria)); } - public override IList Fetch(BookSearchCriteria searchCriteria) + public override IndexerPageableQueryResult Fetch(BookSearchCriteria searchCriteria) { if (!SupportsSearch) { - return new List(); + return new IndexerPageableQueryResult(); } return FetchReleases(g => g.GetSearchRequests(searchCriteria)); } - public override IList Fetch(BasicSearchCriteria searchCriteria) + public override IndexerPageableQueryResult Fetch(BasicSearchCriteria searchCriteria) { if (!SupportsSearch) { - return new List(); + return new IndexerPageableQueryResult(); } return FetchReleases(g => g.GetSearchRequests(searchCriteria)); @@ -116,9 +117,10 @@ namespace NzbDrone.Core.Indexers return requests; } - protected virtual IList FetchReleases(Func pageableRequestChainSelector, bool isRecent = false) + protected virtual IndexerPageableQueryResult FetchReleases(Func pageableRequestChainSelector, bool isRecent = false) { var releases = new List(); + var result = new IndexerPageableQueryResult(); var url = string.Empty; try @@ -153,9 +155,11 @@ namespace NzbDrone.Core.Indexers var page = FetchPage(request, parser); - pagedReleases.AddRange(page); + result.Queries.Add(page); - if (isRecent && page.Any()) + pagedReleases.AddRange(page.Releases); + + if (isRecent && page.Releases.Any()) { if (lastReleaseInfo == null) { @@ -163,8 +167,8 @@ namespace NzbDrone.Core.Indexers break; } - var oldestReleaseDate = page.Select(v => v.PublishDate).Min(); - if (oldestReleaseDate < lastReleaseInfo.PublishDate || page.Any(v => v.DownloadUrl == lastReleaseInfo.DownloadUrl)) + var oldestReleaseDate = page.Releases.Select(v => v.PublishDate).Min(); + if (oldestReleaseDate < lastReleaseInfo.PublishDate || page.Releases.Any(v => v.DownloadUrl == lastReleaseInfo.DownloadUrl)) { fullyUpdated = true; break; @@ -182,7 +186,7 @@ namespace NzbDrone.Core.Indexers break; } - if (!IsFullPage(page)) + if (!IsFullPage(page.Releases)) { break; } @@ -289,7 +293,9 @@ namespace NzbDrone.Core.Indexers _logger.Error(ex, "An error occurred while processing indexer feed. {0}", url); } - return CleanupReleases(releases); + result.Releases = CleanupReleases(releases); + + return result; } public override IndexerCapabilities GetCapabilities() @@ -312,13 +318,18 @@ namespace NzbDrone.Core.Indexers return PageSize != 0 && page.Count >= PageSize; } - protected virtual IList FetchPage(IndexerRequest request, IParseIndexerResponse parser) + protected virtual IndexerQueryResult FetchPage(IndexerRequest request, IParseIndexerResponse parser) { var response = FetchIndexerResponse(request); try { - return parser.ParseResponse(response).ToList(); + return new IndexerQueryResult + { + Releases = parser.ParseResponse(response).ToList(), + ElapsedTime = response.ElapsedTime, + StatusCode = (int)response.HttpResponse.StatusCode + }; } catch (Exception ex) { @@ -339,7 +350,13 @@ namespace NzbDrone.Core.Indexers request.HttpRequest.AllowAutoRedirect = true; - return new IndexerResponse(request, _httpClient.Execute(request.HttpRequest)); + var stopWatch = Stopwatch.StartNew(); + + var response = _httpClient.Execute(request.HttpRequest); + + stopWatch.Stop(); + + return new IndexerResponse(request, response, stopWatch.ElapsedMilliseconds); } protected override void Test(List failures) @@ -366,7 +383,7 @@ namespace NzbDrone.Core.Indexers var releases = FetchPage(firstRequest, parser); - if (releases.Empty()) + if (releases.Releases.Empty()) { return new ValidationFailure(string.Empty, "Query successful, but no results were returned from your indexer. This may be an issue with the indexer or your indexer category settings."); } diff --git a/src/NzbDrone.Core/Indexers/IIndexer.cs b/src/NzbDrone.Core/Indexers/IIndexer.cs index 89e58e520..f8a6e99e7 100644 --- a/src/NzbDrone.Core/Indexers/IIndexer.cs +++ b/src/NzbDrone.Core/Indexers/IIndexer.cs @@ -14,11 +14,11 @@ namespace NzbDrone.Core.Indexers DownloadProtocol Protocol { get; } IndexerPrivacy Privacy { get; } - IList Fetch(MovieSearchCriteria searchCriteria); - IList Fetch(MusicSearchCriteria searchCriteria); - IList Fetch(TvSearchCriteria searchCriteria); - IList Fetch(BookSearchCriteria searchCriteria); - IList Fetch(BasicSearchCriteria searchCriteria); + IndexerPageableQueryResult Fetch(MovieSearchCriteria searchCriteria); + IndexerPageableQueryResult Fetch(MusicSearchCriteria searchCriteria); + IndexerPageableQueryResult Fetch(TvSearchCriteria searchCriteria); + IndexerPageableQueryResult Fetch(BookSearchCriteria searchCriteria); + IndexerPageableQueryResult Fetch(BasicSearchCriteria searchCriteria); IndexerCapabilities GetCapabilities(); } diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index 361b864f7..602bec47a 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -65,11 +65,11 @@ namespace NzbDrone.Core.Indexers protected TSettings Settings => (TSettings)Definition.Settings; - public abstract IList Fetch(MovieSearchCriteria searchCriteria); - public abstract IList Fetch(MusicSearchCriteria searchCriteria); - public abstract IList Fetch(TvSearchCriteria searchCriteria); - public abstract IList Fetch(BookSearchCriteria searchCriteria); - public abstract IList Fetch(BasicSearchCriteria searchCriteria); + public abstract IndexerPageableQueryResult Fetch(MovieSearchCriteria searchCriteria); + public abstract IndexerPageableQueryResult Fetch(MusicSearchCriteria searchCriteria); + public abstract IndexerPageableQueryResult Fetch(TvSearchCriteria searchCriteria); + public abstract IndexerPageableQueryResult Fetch(BookSearchCriteria searchCriteria); + public abstract IndexerPageableQueryResult Fetch(BasicSearchCriteria searchCriteria); public abstract IndexerCapabilities GetCapabilities(); diff --git a/src/NzbDrone.Core/Indexers/IndexerPageableQueryResult.cs b/src/NzbDrone.Core/Indexers/IndexerPageableQueryResult.cs new file mode 100644 index 000000000..f625d9b91 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/IndexerPageableQueryResult.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.Indexers +{ + public class IndexerPageableQueryResult + { + public IndexerPageableQueryResult() + { + Releases = new List(); + Queries = new List(); + } + + public IList Releases { get; set; } + public IList Queries { get; set; } + } +} diff --git a/src/NzbDrone.Core/Indexers/IndexerQueryResult.cs b/src/NzbDrone.Core/Indexers/IndexerQueryResult.cs new file mode 100644 index 000000000..50f1c0cef --- /dev/null +++ b/src/NzbDrone.Core/Indexers/IndexerQueryResult.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.Indexers +{ + public class IndexerQueryResult + { + public IndexerQueryResult() + { + Releases = new List(); + } + + public IList Releases { get; set; } + public long ElapsedTime { get; set; } + public int StatusCode { get; set; } + } +} diff --git a/src/NzbDrone.Core/Indexers/IndexerResponse.cs b/src/NzbDrone.Core/Indexers/IndexerResponse.cs index 1b2dfe60d..d8ddba910 100644 --- a/src/NzbDrone.Core/Indexers/IndexerResponse.cs +++ b/src/NzbDrone.Core/Indexers/IndexerResponse.cs @@ -1,4 +1,4 @@ -using NzbDrone.Common.Http; +using NzbDrone.Common.Http; namespace NzbDrone.Core.Indexers { @@ -7,10 +7,11 @@ namespace NzbDrone.Core.Indexers private readonly IndexerRequest _indexerRequest; private readonly HttpResponse _httpResponse; - public IndexerResponse(IndexerRequest indexerRequest, HttpResponse httpResponse) + public IndexerResponse(IndexerRequest indexerRequest, HttpResponse httpResponse, long elapsedTime = 0) { _indexerRequest = indexerRequest; _httpResponse = httpResponse; + ElapsedTime = elapsedTime; } public IndexerRequest Request => _indexerRequest; @@ -20,5 +21,6 @@ namespace NzbDrone.Core.Indexers public HttpResponse HttpResponse => _httpResponse; public string Content => _httpResponse.Content; + public long ElapsedTime { get; private set; } } }