Handle config updates
This commit is contained in:
parent
f4edca7c27
commit
26a05e6974
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Controller.Channels;
|
using MediaBrowser.Controller.Channels;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
@ -13,6 +14,8 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _serverConfigurationManager;
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
||||||
|
|
||||||
|
private int _metadataRefreshConcurrency = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BaseItemManager"/> class.
|
/// Initializes a new instance of the <see cref="BaseItemManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -21,16 +24,18 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||||
{
|
{
|
||||||
_serverConfigurationManager = serverConfigurationManager;
|
_serverConfigurationManager = serverConfigurationManager;
|
||||||
|
|
||||||
MetadataRefreshThrottler = new Lazy<SemaphoreSlim>(() => {
|
_metadataRefreshConcurrency = GetMetadataRefreshConcurrency();
|
||||||
var concurrency = _serverConfigurationManager.Configuration.LibraryMetadataRefreshConcurrency;
|
SetupMetadataThrottler();
|
||||||
|
|
||||||
if (concurrency <= 0)
|
_serverConfigurationManager.ConfigurationUpdated += (object sender, EventArgs e) =>
|
||||||
|
{
|
||||||
|
int newMetadataRefreshConcurrency = GetMetadataRefreshConcurrency();
|
||||||
|
if (_metadataRefreshConcurrency != newMetadataRefreshConcurrency)
|
||||||
{
|
{
|
||||||
concurrency = Environment.ProcessorCount;
|
_metadataRefreshConcurrency = newMetadataRefreshConcurrency;
|
||||||
|
SetupMetadataThrottler();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return new SemaphoreSlim(concurrency);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -97,5 +102,28 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||||
|
|
||||||
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the metadata refresh throttler.
|
||||||
|
/// </summary>
|
||||||
|
private void SetupMetadataThrottler()
|
||||||
|
{
|
||||||
|
MetadataRefreshThrottler = new Lazy<SemaphoreSlim>(() => new SemaphoreSlim(_metadataRefreshConcurrency));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the metadata refresh concurrency.
|
||||||
|
/// </summary>
|
||||||
|
private int GetMetadataRefreshConcurrency()
|
||||||
|
{
|
||||||
|
var concurrency = _serverConfigurationManager.Configuration.LibraryMetadataRefreshConcurrency;
|
||||||
|
|
||||||
|
if (concurrency <= 0)
|
||||||
|
{
|
||||||
|
concurrency = Environment.ProcessorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return concurrency;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user