The Free Software Media System - Server Backend & API
improve shortcut performance
Luke Pulverentid021e20249c8
diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.csindex 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.Hlspublic 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.csindex 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.Entitiesthrow 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, logif (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.csindex 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; }++ /// <summary>+ /// Serves as a cache+ /// </summary>+ [IgnoreDataMember]+ public Guid ItemId { get; set; }}public enum LinkedChildType@@ -15,24 +22,20 @@ namespace MediaBrowser.Controller.EntitiesShortcut = 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();}}}