1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-22 07:42:28 +00:00

Fixed: Jackett indexer search performance

(cherry picked from commit 29bc660cfbd8fae808b45ddd55c63c7fdd8a2f75)
This commit is contained in:
Taloth Saldono 2021-02-07 19:44:08 +01:00 committed by servarr
parent 294a50e0a3
commit afd3210eb7
3 changed files with 59 additions and 1 deletions

View file

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

View file

@ -109,7 +109,7 @@ private HttpResponse ExecuteRequest(HttpRequest request, CookieContainer cookieC
if (request.RateLimit != TimeSpan.Zero)
{
_rateLimitService.WaitAndPulse(request.Url.Host, request.RateLimit);
_rateLimitService.WaitAndPulse(HttpRateLimitKeyFactory.GetRateLimitKey(request), request.RateLimit);
}
_logger.Trace(request);

View file

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