From 894d87fabb812152c76443afcf1739fda7c578ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 6 Aug 2016 17:10:18 -0400 Subject: [PATCH] add file cache --- .../Providers/DirectoryService.cs | 41 ++++++++----------- .../Manager/MetadataService.cs | 30 -------------- 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index ca9038439e..ee2b28c60a 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -16,7 +16,10 @@ namespace MediaBrowser.Controller.Providers private readonly ConcurrentDictionary> _cache = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); - public DirectoryService(ILogger logger, IFileSystem fileSystem) + private readonly ConcurrentDictionary _fileCache = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + public DirectoryService(ILogger logger, IFileSystem fileSystem) { _logger = logger; _fileSystem = fileSystem; @@ -100,29 +103,19 @@ namespace MediaBrowser.Controller.Providers public FileSystemMetadata GetFile(string path) { - return _fileSystem.GetFileInfo(path); - //var directory = Path.GetDirectoryName(path); - - //if (string.IsNullOrWhiteSpace(directory)) - //{ - // _logger.Debug("Parent path is null for {0}", path); - // return null; - //} - - //try - //{ - // var dict = GetFileSystemDictionary(directory, false); - - // FileSystemMetadata entry; - // dict.TryGetValue(path, out entry); - - // return entry; - //} - //catch (Exception ex) - //{ - // _logger.ErrorException("Error in GetFileSystemDictionary. Directory: :{0}. Original path: {1}", ex, directory, path); - // return null; - //} + FileSystemMetadata file; + if (!_fileCache.TryGetValue(path, out file)) + { + file = _fileSystem.GetFileInfo(path); + + if (file != null) + { + _fileCache.TryAdd(path, file); + } + } + + return file; + //return _fileSystem.GetFileInfo(path); } public IEnumerable GetDirectories(string path) diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index 9c108ac7d3..ac942d1a76 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -349,9 +349,6 @@ namespace MediaBrowser.Providers.Manager if (!runAllProviders) { - // Avoid implicitly captured closure - var currentItem = item; - var providersWithChanges = providers .Where(i => { @@ -361,12 +358,6 @@ namespace MediaBrowser.Providers.Manager return HasChanged(item, hasFileChangeMonitor, options.DirectoryService); } - var hasChangeMonitor = i as IHasChangeMonitor; - if (hasChangeMonitor != null) - { - return HasChanged(item, hasChangeMonitor, currentItem.DateLastSaved, options.DirectoryService); - } - return false; }) .ToList(); @@ -726,27 +717,6 @@ namespace MediaBrowser.Providers.Manager return false; } } - - private bool HasChanged(IHasMetadata item, IHasChangeMonitor changeMonitor, DateTime date, IDirectoryService directoryService) - { - try - { - var hasChanged = changeMonitor.HasChanged(item, directoryService, date); - - //if (hasChanged) - //{ - // Logger.Debug("{0} reports change to {1} since {2}", changeMonitor.GetType().Name, - // item.Path ?? item.Name, date); - //} - - return hasChanged; - } - catch (Exception ex) - { - Logger.ErrorException("Error in {0}.HasChanged", ex, changeMonitor.GetType().Name); - return false; - } - } } public class RefreshResult