diff options
| author | PloughPuff <ploughpuff@protonmail.com> | 2019-03-14 00:43:41 +0000 |
|---|---|---|
| committer | Ploughpuff <ploughpuff@protonmail.com> | 2019-03-14 19:01:17 +0000 |
| commit | f8bb7a7ff4d87d19a43f97fed557aa92a657a50f (patch) | |
| tree | 596073e96783a4702b6170a9f7eb2abc61de6c42 /MediaBrowser.Providers | |
| parent | 6d3e6d800fd8c6d5cb22271e2177946ab286855f (diff) | |
Increased interval to 1050ms and moved to class scope
Review comments from JustAMan.
Diffstat (limited to 'MediaBrowser.Providers')
| -rw-r--r-- | MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index 8a3860d74..a1366e0fd 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -33,6 +33,12 @@ namespace MediaBrowser.Providers.Music public readonly string MusicBrainzBaseUrl; + // The Jellyfin user-agent is unrestricted but source IP must not exceed + // one request per second, therefore we rate limit to avoid throttling. + // Be prudent, use a value slightly above the minimun required. + // https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting + private const long MusicBrainzQueryIntervalMs = 1050u; + public MusicBrainzAlbumProvider( IHttpClient httpClient, IApplicationHost appHost, @@ -715,15 +721,10 @@ namespace MediaBrowser.Providers.Music /// </summary> internal async Task<HttpResponseInfo> GetMusicBrainzResponse(string url, CancellationToken cancellationToken) { - // The Jellyfin user-agent is unrestricted but source IP must not exceed - // one request per second, therefore we rate limit to avoid throttling - // https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting - const long QueryIntervalMs = 1000u; - - // Only delay if necessary - if (_stopWatchMusicBrainz.ElapsedMilliseconds < QueryIntervalMs) + if (_stopWatchMusicBrainz.ElapsedMilliseconds < MusicBrainzQueryIntervalMs) { - var delayMs = QueryIntervalMs - _stopWatchMusicBrainz.ElapsedMilliseconds; + // MusicBrainz is extremely adamant about limiting to one request per second + var delayMs = MusicBrainzQueryIntervalMs - _stopWatchMusicBrainz.ElapsedMilliseconds; await Task.Delay((int)delayMs, cancellationToken).ConfigureAwait(false); } |
