mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Move MetadataRefreshThrottler to BaseItemManager
This commit is contained in:
parent
e8cb9cea7d
commit
f4edca7c27
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using MediaBrowser.Controller.Channels;
|
using MediaBrowser.Controller.Channels;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
@ -19,8 +20,22 @@ namespace MediaBrowser.Controller.BaseItemManager
|
|||||||
public BaseItemManager(IServerConfigurationManager serverConfigurationManager)
|
public BaseItemManager(IServerConfigurationManager serverConfigurationManager)
|
||||||
{
|
{
|
||||||
_serverConfigurationManager = serverConfigurationManager;
|
_serverConfigurationManager = serverConfigurationManager;
|
||||||
|
|
||||||
|
MetadataRefreshThrottler = new Lazy<SemaphoreSlim>(() => {
|
||||||
|
var concurrency = _serverConfigurationManager.Configuration.LibraryMetadataRefreshConcurrency;
|
||||||
|
|
||||||
|
if (concurrency <= 0)
|
||||||
|
{
|
||||||
|
concurrency = Environment.ProcessorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SemaphoreSlim(concurrency);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Lazy<SemaphoreSlim> MetadataRefreshThrottler { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsMetadataFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
|
public bool IsMetadataFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using MediaBrowser.Controller.Entities;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.BaseItemManager
|
namespace MediaBrowser.Controller.BaseItemManager
|
||||||
@ -8,6 +10,11 @@ namespace MediaBrowser.Controller.BaseItemManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBaseItemManager
|
public interface IBaseItemManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the semaphore used to limit the amount of concurrent metadata refreshes.
|
||||||
|
/// </summary>
|
||||||
|
Lazy<SemaphoreSlim> MetadataRefreshThrottler { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is metadata fetcher enabled.
|
/// Is metadata fetcher enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -36,17 +36,6 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Folder : BaseItem
|
public class Folder : BaseItem
|
||||||
{
|
{
|
||||||
private static Lazy<SemaphoreSlim> _metadataRefreshThrottler = new Lazy<SemaphoreSlim>(() => {
|
|
||||||
var concurrency = ConfigurationManager.Configuration.LibraryMetadataRefreshConcurrency;
|
|
||||||
|
|
||||||
if (concurrency <= 0)
|
|
||||||
{
|
|
||||||
concurrency = Environment.ProcessorCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SemaphoreSlim(concurrency);
|
|
||||||
});
|
|
||||||
|
|
||||||
public static IUserViewManager UserViewManager { get; set; }
|
public static IUserViewManager UserViewManager { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -491,7 +480,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
private async Task RefreshAllMetadataForContainer(IMetadataContainer container, MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
private async Task RefreshAllMetadataForContainer(IMetadataContainer container, MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// limit the amount of concurrent metadata refreshes
|
// limit the amount of concurrent metadata refreshes
|
||||||
await RunMetadataRefresh(
|
await ProviderManager.RunMetadataRefresh(
|
||||||
async () =>
|
async () =>
|
||||||
{
|
{
|
||||||
var series = container as Series;
|
var series = container as Series;
|
||||||
@ -518,7 +507,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
if (refreshOptions.RefreshItem(child))
|
if (refreshOptions.RefreshItem(child))
|
||||||
{
|
{
|
||||||
// limit the amount of concurrent metadata refreshes
|
// limit the amount of concurrent metadata refreshes
|
||||||
await RunMetadataRefresh(
|
await ProviderManager.RunMetadataRefresh(
|
||||||
async () => await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false),
|
async () => await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false),
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -1252,26 +1241,6 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs multiple metadata refreshes concurrently.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="action">The action to run.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
|
|
||||||
private static async Task RunMetadataRefresh(Func<Task> action, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
await _metadataRefreshThrottler.Value.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await action().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_metadataRefreshThrottler.Value.Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
public List<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
||||||
{
|
{
|
||||||
if (user == null)
|
if (user == null)
|
||||||
|
@ -45,6 +45,14 @@ namespace MediaBrowser.Controller.Providers
|
|||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task<ItemUpdateType> RefreshSingleItem(BaseItem item, MetadataRefreshOptions options, CancellationToken cancellationToken);
|
Task<ItemUpdateType> RefreshSingleItem(BaseItem item, MetadataRefreshOptions options, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs multiple metadata refreshes concurrently.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action">The action to run.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
|
||||||
|
Task RunMetadataRefresh(Func<Task> action, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image.
|
/// Saves the image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1167,6 +1167,26 @@ namespace MediaBrowser.Providers.Manager
|
|||||||
return RefreshItem(item, options, cancellationToken);
|
return RefreshItem(item, options, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs multiple metadata refreshes concurrently.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action">The action to run.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
|
||||||
|
public async Task RunMetadataRefresh(Func<Task> action, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _baseItemManager.MetadataRefreshThrottler.Value.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await action().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_baseItemManager.MetadataRefreshThrottler.Value.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user