New: Async HttpClient

(cherry picked from commit 0feee191462dd3e5dde66e476e8b4b46a85ec4f0)
This commit is contained in:
Bogdan
2023-07-16 21:07:31 +03:00
parent 29118cda45
commit 1f95bcae4e
58 changed files with 680 additions and 555 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NLog;
@@ -62,7 +63,7 @@ namespace Readarr.Api.V1.Indexers
}
[HttpPost]
public ActionResult<ReleaseResource> Create(ReleaseResource release)
public async Task<ActionResult<ReleaseResource>> DownloadRelease(ReleaseResource release)
{
ValidateResource(release);
@@ -123,7 +124,7 @@ namespace Readarr.Api.V1.Indexers
throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release");
}
_downloadService.DownloadReport(remoteBook);
await _downloadService.DownloadReport(remoteBook);
}
catch (ReleaseDownloadException ex)
{
@@ -135,26 +136,26 @@ namespace Readarr.Api.V1.Indexers
}
[HttpGet]
public List<ReleaseResource> GetReleases(int? bookId, int? authorId)
public async Task<List<ReleaseResource>> GetReleases(int? bookId, int? authorId)
{
if (bookId.HasValue)
{
return GetBookReleases(int.Parse(Request.Query["bookId"]));
return await GetBookReleases(int.Parse(Request.Query["bookId"]));
}
if (authorId.HasValue)
{
return GetAuthorReleases(int.Parse(Request.Query["authorId"]));
return await GetAuthorReleases(int.Parse(Request.Query["authorId"]));
}
return GetRss();
return await GetRss();
}
private List<ReleaseResource> GetBookReleases(int bookId)
private async Task<List<ReleaseResource>> GetBookReleases(int bookId)
{
try
{
var decisions = _releaseSearchService.BookSearch(bookId, true, true, true);
var decisions = await _releaseSearchService.BookSearch(bookId, true, true, true);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(decisions);
return MapDecisions(prioritizedDecisions);
@@ -166,11 +167,11 @@ namespace Readarr.Api.V1.Indexers
}
}
private List<ReleaseResource> GetAuthorReleases(int authorId)
private async Task<List<ReleaseResource>> GetAuthorReleases(int authorId)
{
try
{
var decisions = _releaseSearchService.AuthorSearch(authorId, false, true, true);
var decisions = await _releaseSearchService.AuthorSearch(authorId, false, true, true);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(decisions);
return MapDecisions(prioritizedDecisions);
@@ -182,9 +183,9 @@ namespace Readarr.Api.V1.Indexers
}
}
private List<ReleaseResource> GetRss()
private async Task<List<ReleaseResource>> GetRss()
{
var reports = _rssFetcherAndParser.Fetch();
var reports = await _rssFetcherAndParser.Fetch();
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(decisions);
@@ -195,6 +196,7 @@ namespace Readarr.Api.V1.Indexers
{
var resource = base.MapDecision(decision, initialWeight);
_remoteBookCache.Set(GetCacheKey(resource), decision.RemoteBook, TimeSpan.FromMinutes(30));
return resource;
}

View File

@@ -58,7 +58,7 @@ namespace Readarr.Api.V1.Indexers
lock (PushLock)
{
decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
_downloadDecisionProcessor.ProcessDecisions(decisions);
_downloadDecisionProcessor.ProcessDecisions(decisions).GetAwaiter().GetResult();
}
var firstDecision = decisions.FirstOrDefault();

View File

@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Pending;
@@ -20,7 +21,7 @@ namespace Readarr.Api.V1.Queue
}
[HttpPost("grab/{id:int}")]
public object Grab(int id)
public async Task<object> Grab(int id)
{
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
@@ -29,13 +30,14 @@ namespace Readarr.Api.V1.Queue
throw new NotFoundException();
}
_downloadService.DownloadReport(pendingRelease.RemoteBook);
await _downloadService.DownloadReport(pendingRelease.RemoteBook);
return new { };
}
[HttpPost("grab/bulk")]
public object Grab([FromBody] QueueBulkResource resource)
[Consumes("application/json")]
public async Task<object> Grab([FromBody] QueueBulkResource resource)
{
foreach (var id in resource.Ids)
{
@@ -46,7 +48,7 @@ namespace Readarr.Api.V1.Queue
throw new NotFoundException();
}
_downloadService.DownloadReport(pendingRelease.RemoteBook);
await _downloadService.DownloadReport(pendingRelease.RemoteBook);
}
return new { };