mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 05:25:10 +00:00
Fixed: Jackett indexer search performance
(cherry picked from commit 29bc660cfbd8fae808b45ddd55c63c7fdd8a2f75)
This commit is contained in:
parent
294a50e0a3
commit
afd3210eb7
3 changed files with 59 additions and 1 deletions
|
@ -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 @@ private HttpResponse ExecuteRequest(HttpRequest request, CookieContainer cookieC
|
||||||
|
|
||||||
if (request.RateLimit != TimeSpan.Zero)
|
if (request.RateLimit != TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
_rateLimitService.WaitAndPulse(request.Url.Host, request.RateLimit);
|
_rateLimitService.WaitAndPulse(HttpRateLimitKeyFactory.GetRateLimitKey(request), request.RateLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace(request);
|
_logger.Trace(request);
|
||||||
|
|
28
src/NzbDrone.Common/Http/HttpRateLimitKeyFactory.cs
Normal file
28
src/NzbDrone.Common/Http/HttpRateLimitKeyFactory.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue