speed up ibn item retrieval
This commit is contained in:
parent
0fc6158500
commit
43f7f34b5d
|
@ -574,7 +574,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The images by name item cache
|
/// The images by name item cache
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ConcurrentDictionary<string, object> _imagesByNameItemCache = new ConcurrentDictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
private readonly ConcurrentDictionary<string, BaseItem> _imagesByNameItemCache = new ConcurrentDictionary<string, BaseItem>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generically retrieves an IBN item
|
/// Generically retrieves an IBN item
|
||||||
|
@ -588,7 +588,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
/// <returns>Task{``0}.</returns>
|
/// <returns>Task{``0}.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">
|
/// <exception cref="System.ArgumentNullException">
|
||||||
/// </exception>
|
/// </exception>
|
||||||
private Task<T> GetImagesByNameItem<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true, bool forceCreation = false)
|
private async Task<T> GetImagesByNameItem<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true, bool forceCreation = false)
|
||||||
where T : BaseItem, new()
|
where T : BaseItem, new()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
|
@ -603,18 +603,16 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
var key = Path.Combine(path, FileSystem.GetValidFilename(name));
|
var key = Path.Combine(path, FileSystem.GetValidFilename(name));
|
||||||
|
|
||||||
if (forceCreation)
|
BaseItem obj;
|
||||||
|
|
||||||
|
if (forceCreation || !_imagesByNameItemCache.TryGetValue(key, out obj))
|
||||||
{
|
{
|
||||||
var task = CreateImagesByNameItem<T>(path, name, cancellationToken, allowSlowProviders);
|
obj = await CreateImagesByNameItem<T>(path, name, cancellationToken, allowSlowProviders).ConfigureAwait(false);
|
||||||
|
|
||||||
_imagesByNameItemCache.AddOrUpdate(key, task, (keyName, oldValue) => task);
|
_imagesByNameItemCache.AddOrUpdate(key, obj, (keyName, oldValue) => obj);
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = _imagesByNameItemCache.GetOrAdd(key, keyname => CreateImagesByNameItem<T>(path, name, cancellationToken, allowSlowProviders));
|
return obj as T;
|
||||||
|
|
||||||
return obj as Task<T>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user