mirror of
https://github.com/Prowlarr/Prowlarr
synced 2025-12-06 08:34:28 +01:00
Fixed: (AnimeBytes) Cache result releases
This commit is contained in:
parent
1bcc3b426e
commit
a0e2f3324c
6 changed files with 60 additions and 4 deletions
|
|
@ -351,6 +351,11 @@ class HistoryRow extends Component {
|
||||||
`${data.elapsedTime}ms` :
|
`${data.elapsedTime}ms` :
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
data.cached === '1' ?
|
||||||
|
' (cached)' :
|
||||||
|
null
|
||||||
|
}
|
||||||
</TableRowCell>
|
</TableRowCell>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,14 @@ public static string CalculateCrc(string input)
|
||||||
return $"{mCrc:x8}";
|
return $"{mCrc:x8}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ComputeSha256Hash(string rawData)
|
||||||
|
{
|
||||||
|
using var sha256Hash = SHA256.Create();
|
||||||
|
var hashBytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
|
||||||
|
|
||||||
|
return Convert.ToHexString(hashBytes);
|
||||||
|
}
|
||||||
|
|
||||||
public static string CalculateMd5(string s)
|
public static string CalculateMd5(string s)
|
||||||
{
|
{
|
||||||
// Use input string to calculate MD5 hash
|
// Use input string to calculate MD5 hash
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ public void Handle(IndexerQueryEvent message)
|
||||||
history.Data.Add("Genre", ((BookSearchCriteria)message.Query).Genre ?? string.Empty);
|
history.Data.Add("Genre", ((BookSearchCriteria)message.Query).Genre ?? string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
history.Data.Add("ElapsedTime", message.QueryResult.Response?.ElapsedTime.ToString() ?? string.Empty);
|
history.Data.Add("ElapsedTime", message.QueryResult.Cached ? "0" : message.QueryResult.Response?.ElapsedTime.ToString() ?? string.Empty);
|
||||||
history.Data.Add("Query", message.Query.SearchTerm ?? string.Empty);
|
history.Data.Add("Query", message.Query.SearchTerm ?? string.Empty);
|
||||||
history.Data.Add("QueryType", message.Query.SearchType ?? string.Empty);
|
history.Data.Add("QueryType", message.Query.SearchType ?? string.Empty);
|
||||||
history.Data.Add("Categories", string.Join(",", message.Query.Categories) ?? string.Empty);
|
history.Data.Add("Categories", string.Join(",", message.Query.Categories) ?? string.Empty);
|
||||||
|
|
@ -178,6 +178,7 @@ public void Handle(IndexerQueryEvent message)
|
||||||
history.Data.Add("Host", message.Query.Host ?? string.Empty);
|
history.Data.Add("Host", message.Query.Host ?? string.Empty);
|
||||||
history.Data.Add("QueryResults", message.QueryResult.Releases?.Count.ToString() ?? string.Empty);
|
history.Data.Add("QueryResults", message.QueryResult.Releases?.Count.ToString() ?? string.Empty);
|
||||||
history.Data.Add("Url", message.QueryResult.Response?.Request.Url.FullUri ?? string.Empty);
|
history.Data.Add("Url", message.QueryResult.Response?.Request.Url.FullUri ?? string.Empty);
|
||||||
|
history.Data.Add("Cached", message.QueryResult.Cached ? "1" : "0");
|
||||||
|
|
||||||
_historyRepository.Insert(history);
|
_historyRepository.Insert(history);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Common.Serializer;
|
using NzbDrone.Common.Serializer;
|
||||||
|
|
@ -38,9 +40,12 @@ public class AnimeBytes : TorrentIndexerBase<AnimeBytesSettings>
|
||||||
public override IndexerCapabilities Capabilities => SetCapabilities();
|
public override IndexerCapabilities Capabilities => SetCapabilities();
|
||||||
public override TimeSpan RateLimit => TimeSpan.FromSeconds(4);
|
public override TimeSpan RateLimit => TimeSpan.FromSeconds(4);
|
||||||
|
|
||||||
public AnimeBytes(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger)
|
private readonly ICached<IndexerQueryResult> _queryResultCache;
|
||||||
|
|
||||||
|
public AnimeBytes(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger, ICacheManager cacheManager)
|
||||||
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
|
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
|
||||||
{
|
{
|
||||||
|
_queryResultCache = cacheManager.GetCache<IndexerQueryResult>(GetType(), "QueryResults");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IIndexerRequestGenerator GetRequestGenerator()
|
public override IIndexerRequestGenerator GetRequestGenerator()
|
||||||
|
|
@ -58,6 +63,38 @@ protected override bool CheckIfLoginNeeded(HttpResponse httpResponse)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string BuildQueryResultCacheKey(IndexerRequest request)
|
||||||
|
{
|
||||||
|
return $"{request.HttpRequest.Url.FullUri}.{HashUtil.ComputeSha256Hash(Settings.ToJson())}";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<IndexerQueryResult> FetchPage(IndexerRequest request, IParseIndexerResponse parser)
|
||||||
|
{
|
||||||
|
var cacheKey = BuildQueryResultCacheKey(request);
|
||||||
|
var queryResult = _queryResultCache.Find(cacheKey);
|
||||||
|
|
||||||
|
if (queryResult != null)
|
||||||
|
{
|
||||||
|
queryResult.Cached = true;
|
||||||
|
|
||||||
|
return queryResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
_queryResultCache.ClearExpired();
|
||||||
|
|
||||||
|
queryResult = await base.FetchPage(request, parser);
|
||||||
|
_queryResultCache.Set(cacheKey, queryResult, TimeSpan.FromMinutes(3));
|
||||||
|
|
||||||
|
return queryResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases, SearchCriteriaBase searchCriteria)
|
||||||
|
{
|
||||||
|
var cleanReleases = base.CleanupReleases(releases, searchCriteria);
|
||||||
|
|
||||||
|
return cleanReleases.Select(r => (ReleaseInfo)r.Clone()).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private IndexerCapabilities SetCapabilities()
|
private IndexerCapabilities SetCapabilities()
|
||||||
{
|
{
|
||||||
var caps = new IndexerCapabilities
|
var caps = new IndexerCapabilities
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ public IndexerQueryResult()
|
||||||
|
|
||||||
public IList<ReleaseInfo> Releases { get; set; }
|
public IList<ReleaseInfo> Releases { get; set; }
|
||||||
public HttpResponse Response { get; set; }
|
public HttpResponse Response { get; set; }
|
||||||
|
public bool Cached { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Parser.Model
|
namespace NzbDrone.Core.Parser.Model
|
||||||
{
|
{
|
||||||
public class ReleaseInfo
|
public class ReleaseInfo : ICloneable
|
||||||
{
|
{
|
||||||
public ReleaseInfo()
|
public ReleaseInfo()
|
||||||
{
|
{
|
||||||
|
|
@ -115,5 +114,10 @@ public virtual string ToString(string format)
|
||||||
return ToString();
|
return ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return MemberwiseClone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue