mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-01-21 16:14:39 +00:00
New: Cache searches for 5 days
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
@@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||
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 System.Collections.Generic;
|
||||
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 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
{
|
||||
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 @@ namespace NzbDrone.Core.Http
|
||||
|
||||
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 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
|
||||
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 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
|
||||
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 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
|
||||
.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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user