From 3dc494c02d125a17770f286cf5fe2aad5b56ef38 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 May 2016 14:43:17 -0400 Subject: [PATCH] update FindByPath --- MediaBrowser.Controller/Entities/Folder.cs | 29 ------------------- .../Library/LibraryManager.cs | 20 +++++-------- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 949b333d4a..79cbd7bd30 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1571,35 +1571,6 @@ namespace MediaBrowser.Controller.Entities await Task.WhenAll(tasks).ConfigureAwait(false); } - /// - /// Finds an item by path, recursively - /// - /// The path. - /// BaseItem. - /// - public BaseItem FindByPath(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException(); - } - - if (string.Equals(Path, path, StringComparison.OrdinalIgnoreCase)) - { - return this; - } - - if (PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase)) - { - return this; - } - - return GetRecursiveChildren(i => string.Equals(i.Path, path, StringComparison.OrdinalIgnoreCase) || - (!i.IsFolder && !i.IsInMixedFolder && string.Equals(i.ContainingFolderPath, path, StringComparison.OrdinalIgnoreCase)) || - i.PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase)) - .FirstOrDefault(); - } - public override bool IsPlayed(User user) { var itemsResult = GetItems(new InternalItemsQuery(user) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c95b301722..ec62e733b8 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -787,20 +787,14 @@ namespace MediaBrowser.Server.Implementations.Library IsFolder = isFolder }; - // Only use the database result if there's exactly one item, otherwise we run the risk of returning old data that hasn't been cleaned yet. - var items = GetItemIds(query).Select(GetItemById).Where(i => i != null).ToArray(); + // If this returns multiple items it could be tricky figuring out which one is correct. + // In most cases, the newest one will be and the others obsolete but not yet cleaned up - if (items.Length == 1) - { - return items[0]; - } - - if (items.Length == 0) - { - return null; - } - - return RootFolder.FindByPath(path); + return GetItemIds(query) + .Select(GetItemById) + .Where(i => i != null) + .OrderByDescending(i => i.DateCreated) + .FirstOrDefault(); } ///