improve shortcut performance

pull/702/head
Luke Pulverenti 11 years ago
parent 16fd474ad3
commit d021e20249

@ -66,7 +66,7 @@ namespace MediaBrowser.Api.Playback.Hls
public string PlaylistId { get; set; } public string PlaylistId { get; set; }
} }
[Route("/Videos", "DELETE")] [Route("/Videos/ActiveEncodings", "DELETE")]
[Api(Description = "Stops an encoding process")] [Api(Description = "Stops an encoding process")]
public class StopEncodingProcess public class StopEncodingProcess
{ {

@ -4,7 +4,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO; using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using System; using System;
@ -1140,12 +1139,30 @@ namespace MediaBrowser.Controller.Entities
throw new ArgumentException("Encountered linked child with empty path."); 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) if (item == null)
{ {
Logger.Warn("Unable to find linked item at {0}", info.Path); Logger.Warn("Unable to find linked item at {0}", info.Path);
} }
else
{
// Cache the id for next time
info.ItemId = item.Id;
}
return item; return item;
} }
@ -1215,7 +1232,7 @@ namespace MediaBrowser.Controller.Entities
.Where(i => i != null) .Where(i => i != null)
.ToList(); .ToList();
if (!newShortcutLinks.SequenceEqual(currentShortcutLinks)) if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer()))
{ {
Logger.Info("Shortcut links have changed for {0}", Path); Logger.Info("Shortcut links have changed for {0}", Path);

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections.Generic;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
{ {
@ -7,6 +8,12 @@ namespace MediaBrowser.Controller.Entities
{ {
public string Path { get; set; } public string Path { get; set; }
public LinkedChildType Type { get; set; } public LinkedChildType Type { get; set; }
/// <summary>
/// Serves as a cache
/// </summary>
[IgnoreDataMember]
public Guid ItemId { get; set; }
} }
public enum LinkedChildType public enum LinkedChildType
@ -15,24 +22,20 @@ namespace MediaBrowser.Controller.Entities
Shortcut = 2 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; if (x.Type == y.Type)
var b = (LinkedChild)y;
if (!string.Equals(a.Path, b.Path, StringComparison.OrdinalIgnoreCase))
{ {
return string.Compare(a.Path, b.Path, StringComparison.OrdinalIgnoreCase); return string.Equals(x.Path, y.Path, StringComparison.OrdinalIgnoreCase);
}
if (a.Type != b.Type)
{
return a.Type.CompareTo(b.Type);
} }
return false;
}
return 0; public int GetHashCode(LinkedChild obj)
{
return (obj.Path + obj.Type.ToString()).GetHashCode();
} }
} }
} }

Loading…
Cancel
Save