Kaynağa Gözat

improve shortcut performance

Luke Pulverenti 11 yıl önce
ebeveyn
işleme
d021e20249

+ 1 - 1
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
     {

+ 20 - 3
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);
 

+ 17 - 14
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; }
+
+        /// <summary>
+        /// Serves as a cache
+        /// </summary>
+        [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<LinkedChild>
     {
-        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();
         }
     }
 }