mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-17 02:49:05 -07:00
throttle people requests
This commit is contained in:
parent
8468443410
commit
0181383d1e
@ -76,7 +76,8 @@ namespace MediaBrowser.Api
|
|||||||
ImageRefreshMode = request.ImageRefreshMode,
|
ImageRefreshMode = request.ImageRefreshMode,
|
||||||
ReplaceAllImages = request.ReplaceAllImages,
|
ReplaceAllImages = request.ReplaceAllImages,
|
||||||
ReplaceAllMetadata = request.ReplaceAllMetadata,
|
ReplaceAllMetadata = request.ReplaceAllMetadata,
|
||||||
ForceSave = true
|
ForceSave = true,
|
||||||
|
IsAutomated = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ namespace MediaBrowser.Controller.Providers
|
|||||||
public bool ReplaceAllImages { get; set; }
|
public bool ReplaceAllImages { get; set; }
|
||||||
|
|
||||||
public List<ImageType> ReplaceImages { get; set; }
|
public List<ImageType> ReplaceImages { get; set; }
|
||||||
|
public bool IsAutomated { get; set; }
|
||||||
|
|
||||||
public ImageRefreshOptions(IDirectoryService directoryService)
|
public ImageRefreshOptions(IDirectoryService directoryService)
|
||||||
{
|
{
|
||||||
@ -18,6 +19,7 @@ namespace MediaBrowser.Controller.Providers
|
|||||||
DirectoryService = directoryService;
|
DirectoryService = directoryService;
|
||||||
|
|
||||||
ReplaceImages = new List<ImageType>();
|
ReplaceImages = new List<ImageType>();
|
||||||
|
IsAutomated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsReplacingImage(ImageType type)
|
public bool IsReplacingImage(ImageType type)
|
||||||
|
@ -33,10 +33,12 @@ namespace MediaBrowser.Controller.Providers
|
|||||||
public int? Year { get; set; }
|
public int? Year { get; set; }
|
||||||
public int? IndexNumber { get; set; }
|
public int? IndexNumber { get; set; }
|
||||||
public int? ParentIndexNumber { get; set; }
|
public int? ParentIndexNumber { get; set; }
|
||||||
public DateTime? PremiereDate { get; set; }
|
public DateTime? PremiereDate { get; set; }
|
||||||
|
public bool IsAutomated { get; set; }
|
||||||
|
|
||||||
public ItemLookupInfo()
|
public ItemLookupInfo()
|
||||||
{
|
{
|
||||||
|
IsAutomated = true;
|
||||||
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,7 @@ namespace MediaBrowser.Providers.Manager
|
|||||||
var id = itemOfType.GetLookupInfo();
|
var id = itemOfType.GetLookupInfo();
|
||||||
|
|
||||||
//await FindIdentities(id, cancellationToken).ConfigureAwait(false);
|
//await FindIdentities(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
id.IsAutomated = refreshOptions.IsAutomated;
|
||||||
|
|
||||||
var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, itemImageProvider, cancellationToken).ConfigureAwait(false);
|
var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, itemImageProvider, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ using MediaBrowser.Model.Providers;
|
|||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using MediaBrowser.Providers.Movies;
|
using MediaBrowser.Providers.Movies;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -18,6 +19,7 @@ using System.Net;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommonIO;
|
using CommonIO;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.Net;
|
using MediaBrowser.Model.Net;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.People
|
namespace MediaBrowser.Providers.People
|
||||||
@ -32,14 +34,30 @@ namespace MediaBrowser.Providers.People
|
|||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient)
|
private int _requestCount;
|
||||||
|
private readonly object _requestCountLock = new object();
|
||||||
|
private Timer _requestCountReset;
|
||||||
|
|
||||||
|
public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
|
_logger = logger;
|
||||||
Current = this;
|
Current = this;
|
||||||
|
|
||||||
|
_requestCountReset = new Timer(OnRequestThrottleTimerFired, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRequestThrottleTimerFired(object state)
|
||||||
|
{
|
||||||
|
lock (_requestCountLock)
|
||||||
|
{
|
||||||
|
_requestCount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
@ -79,6 +97,24 @@ namespace MediaBrowser.Providers.People
|
|||||||
return new[] { result };
|
return new[] { result };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (searchInfo.IsAutomated)
|
||||||
|
{
|
||||||
|
lock (_requestCountLock)
|
||||||
|
{
|
||||||
|
var requestCount = _requestCount;
|
||||||
|
|
||||||
|
if (requestCount >= 5)
|
||||||
|
{
|
||||||
|
_logger.Debug("Throttling Tmdb people");
|
||||||
|
|
||||||
|
// This needs to be throttled
|
||||||
|
return new List<RemoteSearchResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_requestCount = requestCount + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var url = string.Format(@"http://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey);
|
var url = string.Format(@"http://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey);
|
||||||
|
|
||||||
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
||||||
|
Loading…
Reference in New Issue
Block a user