From 17bacee0890cb03a579f9469e435d922bbdfdd50 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 21 Nov 2013 15:48:26 -0500 Subject: consolidate Artist & MusicArtist --- .../Library/LibraryManager.cs | 96 ++++++++++++++++++---- 1 file changed, 78 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 6a2df70b1..58a2fcd7e 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -391,10 +391,23 @@ namespace MediaBrowser.Server.Implementations.Library /// The item. private void UpdateItemInLibraryCache(BaseItem item) { - if (!(item is IItemByName)) + if (item is IItemByName) { - LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; }); + var hasDualAccess = item as IHasDualAccess; + if (hasDualAccess != null) + { + if (hasDualAccess.IsAccessedByName) + { + return; + } + } + else + { + return; + } } + + LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; }); } /// @@ -656,16 +669,6 @@ namespace MediaBrowser.Server.Implementations.Library return GetItemByName(ConfigurationManager.ApplicationPaths.GameGenrePath, name); } - /// - /// Gets a Genre - /// - /// The name. - /// Task{Genre}. - public Artist GetArtist(string name) - { - return GetItemByName(ConfigurationManager.ApplicationPaths.ArtistsPath, name); - } - /// /// The us culture /// @@ -687,6 +690,16 @@ namespace MediaBrowser.Server.Implementations.Library return GetItemByName(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture)); } + /// + /// Gets a Genre + /// + /// The name. + /// Task{Genre}. + public MusicArtist GetArtist(string name) + { + return GetItemByName(ConfigurationManager.ApplicationPaths.ArtistsPath, name); + } + /// /// The images by name item cache /// @@ -697,12 +710,12 @@ namespace MediaBrowser.Server.Implementations.Library { if (string.IsNullOrEmpty(path)) { - throw new ArgumentNullException(); + throw new ArgumentNullException("path"); } if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException(); + throw new ArgumentNullException("name"); } var validFilename = _fileSystem.GetValidFilename(name).Trim(); @@ -743,6 +756,20 @@ namespace MediaBrowser.Server.Implementations.Library private Tuple CreateItemByName(string path, string name) where T : BaseItem, new() { + var isArtist = typeof(T) == typeof(MusicArtist); + + if (isArtist) + { + var existing = RootFolder.RecursiveChildren + .OfType() + .FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + + if (existing != null) + { + return new Tuple(false, existing); + } + } + var fileInfo = new DirectoryInfo(path); var isNew = false; @@ -779,6 +806,11 @@ namespace MediaBrowser.Server.Implementations.Library isNew = true; } + if (isArtist) + { + (item as MusicArtist).IsAccessedByName = true; + } + // Set this now so we don't cause additional file system access during provider executions item.ResetResolveArgs(fileInfo); @@ -1363,16 +1395,19 @@ namespace MediaBrowser.Server.Implementations.Library { var item = ItemRepository.RetrieveItem(id); - var folder = item as Folder; - - if (folder != null) + if (item != null && item.IsFolder) { - folder.LoadSavedChildren(); + LoadSavedChildren(item as Folder); } return item; } + private void LoadSavedChildren(Folder item) + { + item.LoadSavedChildren(); + } + private readonly ConcurrentDictionary _fileLocks = new ConcurrentDictionary(); /// @@ -1470,5 +1505,30 @@ namespace MediaBrowser.Server.Implementations.Library return collectionTypes.Count == 1 ? collectionTypes[0] : null; } + + + public IEnumerable GetAllArtists() + { + return GetAllArtists(RootFolder.RecursiveChildren); + } + + public IEnumerable GetAllArtists(IEnumerable items) + { + return items + .OfType