From b721aab2ba9dac5e5e3a7b53c066791d23e83bc2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 12 Apr 2013 14:59:06 -0400 Subject: [PATCH] always replace cached data during people validation --- .../Library/LibraryManager.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 91187b687..d397b1548 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -516,10 +516,11 @@ namespace MediaBrowser.Server.Implementations.Library /// The name. /// The cancellation token. /// if set to true [allow slow providers]. + /// if set to true [force creation]. /// Task{Person}. - private Task GetPerson(string name, CancellationToken cancellationToken, bool allowSlowProviders = false) + private Task GetPerson(string name, CancellationToken cancellationToken, bool allowSlowProviders = false, bool forceCreation = false) { - return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders); + return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders, forceCreation); } /// @@ -579,9 +580,11 @@ namespace MediaBrowser.Server.Implementations.Library /// The name. /// The cancellation token. /// if set to true [allow slow providers]. + /// if set to true [force creation]. /// Task{``0}. - /// - private Task GetImagesByNameItem(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true) + /// + /// + private Task GetImagesByNameItem(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true, bool forceCreation = false) where T : BaseItem, new() { if (string.IsNullOrEmpty(path)) @@ -596,6 +599,15 @@ namespace MediaBrowser.Server.Implementations.Library var key = Path.Combine(path, FileSystem.GetValidFilename(name)); + if (forceCreation) + { + var task = CreateImagesByNameItem(path, name, cancellationToken, allowSlowProviders); + + _imagesByNameItemCache.AddOrUpdate(key, task, (keyName, oldValue) => task); + + return task; + } + var obj = _imagesByNameItemCache.GetOrAdd(key, keyname => CreateImagesByNameItem(path, name, cancellationToken, allowSlowProviders)); return obj as Task; @@ -676,9 +688,6 @@ namespace MediaBrowser.Server.Implementations.Library /// Task. public async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) { - // Clear the IBN cache - _imagesByNameItemCache.Clear(); - const int maxTasks = 250; var tasks = new List(); @@ -713,7 +722,7 @@ namespace MediaBrowser.Server.Implementations.Library try { - await GetPerson(currentPerson.Name, cancellationToken, allowSlowProviders: true).ConfigureAwait(false); + await GetPerson(currentPerson.Name, cancellationToken, true, true).ConfigureAwait(false); } catch (IOException ex) {