Fixed: Jackett indexer search performance

(cherry picked from commit 29bc660cfbd8fae808b45ddd55c63c7fdd8a2f75)
pull/1975/head
Taloth Saldono 4 years ago committed by servarr
parent 294a50e0a3
commit afd3210eb7

@ -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);
}
}
}

@ -109,7 +109,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…
Cancel
Save