Generalized RateLimit logic to all indexers based on indexer id

This commit is contained in:
Taloth Saldono
2021-03-16 21:52:21 +00:00
committed by ta264
parent c8c37435be
commit d61daeac8e
9 changed files with 76 additions and 66 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ namespace NzbDrone.Common.Http
if (request.RateLimit != TimeSpan.Zero)
{
_rateLimitService.WaitAndPulse(HttpRateLimitKeyFactory.GetRateLimitKey(request), request.RateLimit);
_rateLimitService.WaitAndPulse(request.Url.Host, request.RateLimitKey, request.RateLimit);
}
_logger.Trace(request);
@@ -1,28 +0,0 @@
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;
}
}
}
+1
View File
@@ -45,6 +45,7 @@ namespace NzbDrone.Common.Http
public bool StoreResponseCookie { get; set; }
public TimeSpan RequestTimeout { get; set; }
public TimeSpan RateLimit { get; set; }
public string RateLimitKey { get; set; }
public Stream ResponseStream { get; set; }
public override string ToString()