From 5cb74690284105db70a467ab77c2af3f44e42348 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Nov 2017 16:51:23 -0500 Subject: support track selection before playback --- .../Providers/DirectoryService.cs | 52 ++++++++++++---------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Controller/Providers/DirectoryService.cs') diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index d957470d3b..d673198fdc 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -14,11 +14,11 @@ namespace MediaBrowser.Controller.Providers private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private readonly ConcurrentDictionary _cache = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _cache = new Dictionary(StringComparer.OrdinalIgnoreCase); - private readonly ConcurrentDictionary _fileCache = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _fileCache = new Dictionary(StringComparer.OrdinalIgnoreCase); + + private readonly Dictionary> _filePathCache = new Dictionary>(StringComparer.OrdinalIgnoreCase); public DirectoryService(ILogger logger, IFileSystem fileSystem) { @@ -32,11 +32,6 @@ namespace MediaBrowser.Controller.Providers } public FileSystemMetadata[] GetFileSystemEntries(string path) - { - return GetFileSystemEntries(path, false); - } - - private FileSystemMetadata[] GetFileSystemEntries(string path, bool clearCache) { if (string.IsNullOrWhiteSpace(path)) { @@ -45,13 +40,6 @@ namespace MediaBrowser.Controller.Providers FileSystemMetadata[] entries; - if (clearCache) - { - FileSystemMetadata[] removed; - - _cache.TryRemove(path, out removed); - } - if (!_cache.TryGetValue(path, out entries)) { //_logger.Debug("Getting files for " + path); @@ -66,21 +54,17 @@ namespace MediaBrowser.Controller.Providers entries = new FileSystemMetadata[] { }; } - _cache.TryAdd(path, entries); + //_cache.TryAdd(path, entries); + _cache[path] = entries; } return entries; } public List GetFiles(string path) - { - return GetFiles(path, false); - } - - public List GetFiles(string path, bool clearCache) { var list = new List(); - var items = GetFileSystemEntries(path, clearCache); + var items = GetFileSystemEntries(path); foreach (var item in items) { if (!item.IsDirectory) @@ -100,7 +84,8 @@ namespace MediaBrowser.Controller.Providers if (file != null && file.Exists) { - _fileCache.TryAdd(path, file); + //_fileCache.TryAdd(path, file); + _fileCache[path] = file; } else { @@ -111,5 +96,24 @@ namespace MediaBrowser.Controller.Providers return file; //return _fileSystem.GetFileInfo(path); } + + public List GetFilePaths(string path) + { + return GetFilePaths(path, false); + } + + public List GetFilePaths(string path, bool clearCache) + { + List result; + if (clearCache || !_filePathCache.TryGetValue(path, out result)) + { + result = _fileSystem.GetFilePaths(path).ToList(); + + _filePathCache[path] = result; + } + + return result; + } + } } -- cgit v1.2.3