From d021e20249c85ab96783e1347d95f826a816ff9b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Oct 2013 11:24:32 -0400 Subject: [PATCH] improve shortcut performance --- .../Playback/Hls/HlsSegmentService.cs | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 23 ++++++++++++-- .../Entities/LinkedChild.cs | 31 ++++++++++--------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index be7aadec09..e9f7e48b19 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -66,7 +66,7 @@ namespace MediaBrowser.Api.Playback.Hls public string PlaylistId { get; set; } } - [Route("/Videos", "DELETE")] + [Route("/Videos/ActiveEncodings", "DELETE")] [Api(Description = "Stops an encoding process")] public class StopEncodingProcess { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 5e6b02e08e..95a68c009b 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -4,7 +4,6 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; -using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; @@ -1140,12 +1139,30 @@ namespace MediaBrowser.Controller.Entities throw new ArgumentException("Encountered linked child with empty path."); } - var item = LibraryManager.RootFolder.FindByPath(info.Path); + BaseItem item = null; + // First get using the cached Id + if (info.ItemId != Guid.Empty) + { + item = LibraryManager.GetItemById(info.ItemId); + } + + // If still null, search by path + if (item == null) + { + item = LibraryManager.RootFolder.FindByPath(info.Path); + } + + // If still null, log if (item == null) { Logger.Warn("Unable to find linked item at {0}", info.Path); } + else + { + // Cache the id for next time + info.ItemId = item.Id; + } return item; } @@ -1215,7 +1232,7 @@ namespace MediaBrowser.Controller.Entities .Where(i => i != null) .ToList(); - if (!newShortcutLinks.SequenceEqual(currentShortcutLinks)) + if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer())) { Logger.Info("Shortcut links have changed for {0}", Path); diff --git a/MediaBrowser.Controller/Entities/LinkedChild.cs b/MediaBrowser.Controller/Entities/LinkedChild.cs index edc5a7ac88..e01d55c68d 100644 --- a/MediaBrowser.Controller/Entities/LinkedChild.cs +++ b/MediaBrowser.Controller/Entities/LinkedChild.cs @@ -1,5 +1,6 @@ using System; -using System.Collections; +using System.Collections.Generic; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities { @@ -7,6 +8,12 @@ namespace MediaBrowser.Controller.Entities { public string Path { get; set; } public LinkedChildType Type { get; set; } + + /// + /// Serves as a cache + /// + [IgnoreDataMember] + public Guid ItemId { get; set; } } public enum LinkedChildType @@ -15,24 +22,20 @@ namespace MediaBrowser.Controller.Entities Shortcut = 2 } - public class LinkedChildComparer : IComparer + public class LinkedChildComparer : IEqualityComparer { - public int Compare(object x, object y) + public bool Equals(LinkedChild x, LinkedChild y) { - var a = (LinkedChild)x; - - var b = (LinkedChild)y; - - if (!string.Equals(a.Path, b.Path, StringComparison.OrdinalIgnoreCase)) + if (x.Type == y.Type) { - return string.Compare(a.Path, b.Path, StringComparison.OrdinalIgnoreCase); - } - if (a.Type != b.Type) - { - return a.Type.CompareTo(b.Type); + return string.Equals(x.Path, y.Path, StringComparison.OrdinalIgnoreCase); } + return false; + } - return 0; + public int GetHashCode(LinkedChild obj) + { + return (obj.Path + obj.Type.ToString()).GetHashCode(); } } }