Merge pull request #1370 from MediaBrowser/master
throttle tmdb requests
This commit is contained in:
commit
3231c07ae1
|
@ -366,14 +366,27 @@ namespace MediaBrowser.Providers.Movies
|
||||||
return mainResult;
|
return mainResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long _lastRequestTicks;
|
||||||
|
private static int requestIntervalMs = 100;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the movie db response.
|
/// Gets the movie db response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal Task<Stream> GetMovieDbResponse(HttpRequestOptions options)
|
internal async Task<Stream> GetMovieDbResponse(HttpRequestOptions options)
|
||||||
{
|
{
|
||||||
options.ResourcePool = MovieDbResourcePool;
|
var delayTicks = (requestIntervalMs * 10000) - (DateTime.UtcNow.Ticks - _lastRequestTicks);
|
||||||
|
var delayMs = Math.Min(delayTicks / 10000, requestIntervalMs);
|
||||||
|
|
||||||
return _httpClient.Get(options);
|
if (delayMs > 0)
|
||||||
|
{
|
||||||
|
_logger.Debug("Throttling Tmdb by {0} ms", delayMs);
|
||||||
|
await Task.Delay(Convert.ToInt32(delayMs)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.ResourcePool = MovieDbResourcePool;
|
||||||
|
_lastRequestTicks = DateTime.UtcNow.Ticks;
|
||||||
|
|
||||||
|
return await _httpClient.Get(options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TheMovieDbOptions GetTheMovieDbOptions()
|
public TheMovieDbOptions GetTheMovieDbOptions()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user