mirror of
https://github.com/Readarr/Readarr
synced 2026-05-08 12:42:51 +02: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 Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common.Cache;
|
using NzbDrone.Common.Cache;
|
||||||
|
|
@ -33,7 +33,7 @@ protected void UseRealHttp()
|
||||||
var httpClient = Mocker.Resolve<IHttpClient>();
|
var httpClient = Mocker.Resolve<IHttpClient>();
|
||||||
Mocker.GetMock<ICachedHttpResponseService>()
|
Mocker.GetMock<ICachedHttpResponseService>()
|
||||||
.Setup(x => x.Get(It.IsAny<HttpRequest>(), It.IsAny<bool>(), It.IsAny<TimeSpan>()))
|
.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 FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Books;
|
using NzbDrone.Core.Books;
|
||||||
|
using NzbDrone.Core.Http;
|
||||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||||
using NzbDrone.Core.Profiles.Metadata;
|
using NzbDrone.Core.Profiles.Metadata;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
@ -19,6 +21,11 @@ public void Setup()
|
||||||
{
|
{
|
||||||
UseRealHttp();
|
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();
|
var metadataProfile = new MetadataProfile();
|
||||||
|
|
||||||
Mocker.GetMock<IMetadataProfileService>()
|
Mocker.GetMock<IMetadataProfileService>()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ namespace NzbDrone.Core.Http
|
||||||
public interface ICachedHttpResponseService
|
public interface ICachedHttpResponseService
|
||||||
{
|
{
|
||||||
HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl);
|
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
|
public class CachedHttpResponseService : ICachedHttpResponseService
|
||||||
|
|
@ -54,5 +56,12 @@ public HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl)
|
||||||
|
|
||||||
return result;
|
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)/",
|
private static readonly Regex NoPhotoRegex = new Regex(@"/nophoto/(book|user)/",
|
||||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
|
||||||
private readonly ICachedHttpResponseService _cachedHttpClient;
|
private readonly ICachedHttpResponseService _cachedHttpClient;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
private readonly IAuthorService _authorService;
|
private readonly IAuthorService _authorService;
|
||||||
|
|
@ -38,15 +37,13 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB
|
||||||
private readonly IHttpRequestBuilderFactory _searchBuilder;
|
private readonly IHttpRequestBuilderFactory _searchBuilder;
|
||||||
private readonly ICached<HashSet<string>> _cache;
|
private readonly ICached<HashSet<string>> _cache;
|
||||||
|
|
||||||
public GoodreadsProxy(IHttpClient httpClient,
|
public GoodreadsProxy(ICachedHttpResponseService cachedHttpClient,
|
||||||
ICachedHttpResponseService cachedHttpClient,
|
|
||||||
IAuthorService authorService,
|
IAuthorService authorService,
|
||||||
IBookService bookService,
|
IBookService bookService,
|
||||||
IEditionService editionService,
|
IEditionService editionService,
|
||||||
Logger logger,
|
Logger logger,
|
||||||
ICacheManager cacheManager)
|
ICacheManager cacheManager)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
|
||||||
_cachedHttpClient = cachedHttpClient;
|
_cachedHttpClient = cachedHttpClient;
|
||||||
_authorService = authorService;
|
_authorService = authorService;
|
||||||
_bookService = bookService;
|
_bookService = bookService;
|
||||||
|
|
@ -482,7 +479,7 @@ public List<Book> SearchByField(string field, string query)
|
||||||
.AddQueryParam("q", query)
|
.AddQueryParam("q", query)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var result = _httpClient.Get<List<SearchJsonResource>>(httpRequest);
|
var result = _cachedHttpClient.Get<List<SearchJsonResource>>(httpRequest, true, TimeSpan.FromDays(5));
|
||||||
|
|
||||||
return result.Resource.SelectList(MapJsonSearchResult);
|
return result.Resource.SelectList(MapJsonSearchResult);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue