From 7756a5bb3a4cf0fc902fbe09540f2a2a715ffbc8 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Tue, 12 Mar 2013 01:40:24 -0400 Subject: [PATCH] fixes #29 - People are refreshing on every configuration change --- .../Library/LibraryManager.cs | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index b99bc4f97..549ea9be2 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -9,6 +9,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.ScheduledTasks; using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations.ScheduledTasks; @@ -121,6 +122,8 @@ namespace MediaBrowser.Server.Implementations.Library ConfigurationManager = configurationManager; ConfigurationManager.ConfigurationUpdated += kernel_ConfigurationUpdated; + + RecordConfigurationValues(configurationManager.Configuration); } /// @@ -174,6 +177,15 @@ namespace MediaBrowser.Server.Implementations.Library } } + private bool _internetProvidersEnabled; + private bool _peopleImageFetchingEnabled; + + private void RecordConfigurationValues(ServerConfiguration configuration) + { + _internetProvidersEnabled = configuration.EnableInternetProviders; + _peopleImageFetchingEnabled = configuration.InternetProviderExcludeTypes == null || !configuration.InternetProviderExcludeTypes.Contains(typeof(Person).Name, StringComparer.OrdinalIgnoreCase); + } + /// /// Handles the ConfigurationUpdated event of the kernel control. /// @@ -181,23 +193,30 @@ namespace MediaBrowser.Server.Implementations.Library /// The instance containing the event data. void kernel_ConfigurationUpdated(object sender, EventArgs e) { - //// Figure out whether or not we should refresh people after the update is finished - //var refreshPeopleAfterUpdate = !oldConfiguration.EnableInternetProviders && config.EnableInternetProviders; + var config = ConfigurationManager.Configuration; - //// This is true if internet providers has just been turned on, or if People have just been removed from InternetProviderExcludeTypes - //if (!refreshPeopleAfterUpdate) - //{ - // var oldConfigurationFetchesPeopleImages = oldConfiguration.InternetProviderExcludeTypes == null || !oldConfiguration.InternetProviderExcludeTypes.Contains(typeof(Person).Name, StringComparer.OrdinalIgnoreCase); - // var newConfigurationFetchesPeopleImages = config.InternetProviderExcludeTypes == null || !config.InternetProviderExcludeTypes.Contains(typeof(Person).Name, StringComparer.OrdinalIgnoreCase); + // Figure out whether or not we should refresh people after the update is finished + var refreshPeopleAfterUpdate = !_internetProvidersEnabled && config.EnableInternetProviders; - // refreshPeopleAfterUpdate = newConfigurationFetchesPeopleImages && !oldConfigurationFetchesPeopleImages; - //} + // This is true if internet providers has just been turned on, or if People have just been removed from InternetProviderExcludeTypes + if (!refreshPeopleAfterUpdate) + { + var newConfigurationFetchesPeopleImages = config.InternetProviderExcludeTypes == null || !config.InternetProviderExcludeTypes.Contains(typeof(Person).Name, StringComparer.OrdinalIgnoreCase); + + refreshPeopleAfterUpdate = newConfigurationFetchesPeopleImages && !_peopleImageFetchingEnabled; + } + + RecordConfigurationValues(config); Task.Run(() => { // Any number of configuration settings could change the way the library is refreshed, so do that now _taskManager.CancelIfRunningAndQueue(); - _taskManager.CancelIfRunningAndQueue(); + + if (refreshPeopleAfterUpdate) + { + _taskManager.CancelIfRunningAndQueue(); + } }); }