Fixed: Jackett indexer search performance
This commit is contained in:
parent
f8b8afdaa2
commit
29bc660cfb
|
@ -0,0 +1,30 @@
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Common.Test.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class HttpRateLimitKeyFactoryFixture
|
||||
{
|
||||
[TestCase("http://127.0.0.2:9117/jackett/api/v2.0/indexers/viva/results/torznab/api?t=search&cat=5000,5070,100030,100041", "127.0.0.2:9117/jackett/api/v2.0/indexers/viva")]
|
||||
public void should_detect_jackett(string url, string expectedKey)
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
|
||||
var key = HttpRateLimitKeyFactory.GetRateLimitKey(request);
|
||||
|
||||
key.Should().Be(expectedKey);
|
||||
}
|
||||
|
||||
[TestCase("http://127.0.0.2:9117/jackett", "127.0.0.2")]
|
||||
public void should_default_to_host(string url, string expectedKey)
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
|
||||
var key = HttpRateLimitKeyFactory.GetRateLimitKey(request);
|
||||
|
||||
key.Should().Be(expectedKey);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -111,7 +111,7 @@ namespace NzbDrone.Common.Http
|
|||
|
||||
if (request.RateLimit != TimeSpan.Zero)
|
||||
{
|
||||
_rateLimitService.WaitAndPulse(request.Url.Host, request.RateLimit);
|
||||
_rateLimitService.WaitAndPulse(HttpRateLimitKeyFactory.GetRateLimitKey(request), request.RateLimit);
|
||||
}
|
||||
|
||||
_logger.Trace(request);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public static class HttpRateLimitKeyFactory
|
||||
{
|
||||
// Use a different key for jackett instances to prevent hitting the ratelimit for multiple separate indexers.
|
||||
private static readonly Regex _regex = new Regex(@"^https?://(.+/jackett/api/v2.0/indexers/\w+)/", RegexOptions.Compiled);
|
||||
|
||||
public static string GetRateLimitKey(HttpRequest request)
|
||||
{
|
||||
var match = _regex.Match(request.Url.ToString());
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups[1].Value;
|
||||
}
|
||||
|
||||
return request.Url.Host;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue