mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
commit
5571bc98f3
4 changed files with 14 additions and 56 deletions
|
@ -186,20 +186,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The _semaphoreLocks
|
|
||||||
/// </summary>
|
|
||||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks = new ConcurrentDictionary<string, SemaphoreSlim>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the lock.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url">The filename.</param>
|
|
||||||
/// <returns>System.Object.</returns>
|
|
||||||
private SemaphoreSlim GetLock(string url)
|
|
||||||
{
|
|
||||||
return _semaphoreLocks.GetOrAdd(url, key => new SemaphoreSlim(1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the response internal.
|
/// Gets the response internal.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -279,18 +265,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
var semaphore = GetLock(url);
|
|
||||||
|
|
||||||
await semaphore.WaitAsync(options.CancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
|
|
||||||
if (response != null)
|
|
||||||
{
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
|
response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.OK)
|
if (response.StatusCode == HttpStatusCode.OK)
|
||||||
|
@ -300,11 +274,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
semaphore.Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
|
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
|
||||||
{
|
{
|
||||||
|
@ -347,14 +316,13 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
||||||
|
|
||||||
using (var responseStream = response.Content)
|
using (var responseStream = response.Content)
|
||||||
{
|
|
||||||
using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
|
||||||
{
|
{
|
||||||
var memoryStream = new MemoryStream();
|
var memoryStream = new MemoryStream();
|
||||||
|
|
||||||
await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||||
|
|
||||||
memoryStream.Position = 0;
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
|
using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.None, true))
|
||||||
|
{
|
||||||
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
|
||||||
memoryStream.Position = 0;
|
memoryStream.Position = 0;
|
||||||
|
|
|
@ -297,12 +297,6 @@ namespace MediaBrowser.Providers.Music
|
||||||
ResourcePool = _musicBrainzResourcePool
|
ResourcePool = _musicBrainzResourcePool
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isSearch)
|
|
||||||
{
|
|
||||||
options.CacheMode = CacheMode.Unconditional;
|
|
||||||
options.CacheLength = TimeSpan.FromDays(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var xml = await _httpClient.Get(options).ConfigureAwait(false))
|
using (var xml = await _httpClient.Get(options).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
using (var oReader = new StreamReader(xml, Encoding.UTF8))
|
using (var oReader = new StreamReader(xml, Encoding.UTF8))
|
||||||
|
|
|
@ -99,9 +99,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
ResourcePool = OmdbProvider.ResourcePool,
|
ResourcePool = OmdbProvider.ResourcePool,
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken
|
||||||
CacheMode = CacheMode.Unconditional,
|
|
||||||
CacheLength = TimeSpan.FromDays(2)
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,9 +43,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
ResourcePool = ResourcePool,
|
ResourcePool = ResourcePool,
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken
|
||||||
CacheMode = CacheMode.Unconditional,
|
|
||||||
CacheLength = TimeSpan.FromDays(7)
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue