mirror of
https://github.com/Readarr/Readarr
synced 2025-12-28 11:13:22 +01:00
New: Cache searches for 5 days
This commit is contained in:
parent
996841db45
commit
d078dacaab
4 changed files with 20 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
|
@ -33,7 +33,7 @@ protected void UseRealHttp()
|
|||
var httpClient = Mocker.Resolve<IHttpClient>();
|
||||
Mocker.GetMock<ICachedHttpResponseService>()
|
||||
.Setup(x => x.Get(It.IsAny<HttpRequest>(), It.IsAny<bool>(), It.IsAny<TimeSpan>()))
|
||||
.Returns((HttpRequest request, bool useCavhe, TimeSpan ttl) => httpClient.Get(request));
|
||||
.Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get(request));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Http;
|
||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
|
@ -19,6 +21,11 @@ public void Setup()
|
|||
{
|
||||
UseRealHttp();
|
||||
|
||||
var httpClient = Mocker.Resolve<IHttpClient>();
|
||||
Mocker.GetMock<ICachedHttpResponseService>()
|
||||
.Setup(x => x.Get<List<SearchJsonResource>>(It.IsAny<HttpRequest>(), It.IsAny<bool>(), It.IsAny<TimeSpan>()))
|
||||
.Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get<List<SearchJsonResource>>(request));
|
||||
|
||||
var metadataProfile = new MetadataProfile();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ namespace NzbDrone.Core.Http
|
|||
public interface ICachedHttpResponseService
|
||||
{
|
||||
HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl);
|
||||
HttpResponse<T> Get<T>(HttpRequest request, bool useCache, TimeSpan ttl)
|
||||
where T : new();
|
||||
}
|
||||
|
||||
public class CachedHttpResponseService : ICachedHttpResponseService
|
||||
|
|
@ -54,5 +56,12 @@ public HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public HttpResponse<T> Get<T>(HttpRequest request, bool useCache, TimeSpan ttl)
|
||||
where T : new()
|
||||
{
|
||||
var response = Get(request, useCache, ttl);
|
||||
return new HttpResponse<T>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB
|
|||
private static readonly Regex NoPhotoRegex = new Regex(@"/nophoto/(book|user)/",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly ICachedHttpResponseService _cachedHttpClient;
|
||||
private readonly Logger _logger;
|
||||
private readonly IAuthorService _authorService;
|
||||
|
|
@ -38,15 +37,13 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB
|
|||
private readonly IHttpRequestBuilderFactory _searchBuilder;
|
||||
private readonly ICached<HashSet<string>> _cache;
|
||||
|
||||
public GoodreadsProxy(IHttpClient httpClient,
|
||||
ICachedHttpResponseService cachedHttpClient,
|
||||
public GoodreadsProxy(ICachedHttpResponseService cachedHttpClient,
|
||||
IAuthorService authorService,
|
||||
IBookService bookService,
|
||||
IEditionService editionService,
|
||||
Logger logger,
|
||||
ICacheManager cacheManager)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_cachedHttpClient = cachedHttpClient;
|
||||
_authorService = authorService;
|
||||
_bookService = bookService;
|
||||
|
|
@ -482,7 +479,7 @@ public List<Book> SearchByField(string field, string query)
|
|||
.AddQueryParam("q", query)
|
||||
.Build();
|
||||
|
||||
var result = _httpClient.Get<List<SearchJsonResource>>(httpRequest);
|
||||
var result = _cachedHttpClient.Get<List<SearchJsonResource>>(httpRequest, true, TimeSpan.FromDays(5));
|
||||
|
||||
return result.Resource.SelectList(MapJsonSearchResult);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue