update movie db provider

This commit is contained in:
Luke Pulverenti 2015-11-12 13:44:46 -05:00
parent b5a7483fcc
commit 8d37d66fa5

View file

@ -160,9 +160,7 @@ namespace MediaBrowser.Providers.Movies
{ {
Url = string.Format(TmdbConfigUrl, ApiKey), Url = string.Format(TmdbConfigUrl, ApiKey),
CancellationToken = cancellationToken, CancellationToken = cancellationToken,
AcceptHeader = AcceptHeader, AcceptHeader = AcceptHeader
CacheMode = CacheMode.Unconditional,
CacheLength = TimeSpan.FromDays(1)
}).ConfigureAwait(false)) }).ConfigureAwait(false))
{ {
@ -368,27 +366,14 @@ namespace MediaBrowser.Providers.Movies
return mainResult; return mainResult;
} }
private static long _lastRequestTicks;
/// <summary> /// <summary>
/// Gets the movie db response. /// Gets the movie db response.
/// </summary> /// </summary>
internal async Task<Stream> GetMovieDbResponse(HttpRequestOptions options) internal Task<Stream> GetMovieDbResponse(HttpRequestOptions options)
{ {
var requestIntervalMs = 250;
var delayTicks = (requestIntervalMs * 10000) - (DateTime.UtcNow.Ticks - _lastRequestTicks);
var delayMs = Math.Min(delayTicks / 10000, requestIntervalMs);
if (delayMs > 0)
{
_logger.Debug("Throttling Tmdb by {0} ms", delayMs);
await Task.Delay(Convert.ToInt32(delayMs)).ConfigureAwait(false);
}
options.ResourcePool = MovieDbResourcePool; options.ResourcePool = MovieDbResourcePool;
_lastRequestTicks = DateTime.UtcNow.Ticks;
return await _httpClient.Get(options).ConfigureAwait(false); return _httpClient.Get(options);
} }
public TheMovieDbOptions GetTheMovieDbOptions() public TheMovieDbOptions GetTheMovieDbOptions()