cleanup repeated querying within CollectionFolder
This commit is contained in:
parent
cb839f9f25
commit
d580abcd65
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -69,37 +68,41 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return NullTaskResult;
|
return NullTaskResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<LinkedChild> _linkedChildren;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Our children are actually just references to the ones in the physical root...
|
/// Our children are actually just references to the ones in the physical root...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The linked children.</value>
|
/// <value>The linked children.</value>
|
||||||
public override List<LinkedChild> LinkedChildren
|
public override List<LinkedChild> LinkedChildren
|
||||||
{
|
{
|
||||||
get
|
get { return _linkedChildren ?? (_linkedChildren = GetLinkedChildrenInternal()); }
|
||||||
{
|
|
||||||
Dictionary<string, string> locationsDicionary;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
locationsDicionary = ResolveArgs.PhysicalLocations.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
|
||||||
return new List<LinkedChild>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return LibraryManager.RootFolder.Children
|
|
||||||
.OfType<Folder>()
|
|
||||||
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path))
|
|
||||||
.SelectMany(c => c.LinkedChildren).ToList();
|
|
||||||
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
base.LinkedChildren = value;
|
base.LinkedChildren = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private List<LinkedChild> GetLinkedChildrenInternal()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> locationsDicionary;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
locationsDicionary = ResolveArgs.PhysicalLocations.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
||||||
|
return new List<LinkedChild>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return LibraryManager.RootFolder.Children
|
||||||
|
.OfType<Folder>()
|
||||||
|
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path))
|
||||||
|
.SelectMany(c => c.LinkedChildren).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<BaseItem> _actualChildren;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Our children are actually just references to the ones in the physical root...
|
/// Our children are actually just references to the ones in the physical root...
|
||||||
|
@ -107,26 +110,34 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <value>The actual children.</value>
|
/// <value>The actual children.</value>
|
||||||
protected override IEnumerable<BaseItem> ActualChildren
|
protected override IEnumerable<BaseItem> ActualChildren
|
||||||
{
|
{
|
||||||
get
|
get { return _actualChildren ?? (_actualChildren = GetActualChildren()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<BaseItem> GetActualChildren()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> locationsDicionary;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, string> locationsDicionary;
|
locationsDicionary = ResolveArgs.PhysicalLocations.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
locationsDicionary = ResolveArgs.PhysicalLocations.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
|
||||||
return new BaseItem[] { };
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
LibraryManager.RootFolder.Children
|
|
||||||
.OfType<Folder>()
|
|
||||||
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path))
|
|
||||||
.SelectMany(c => c.Children);
|
|
||||||
}
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
||||||
|
return new BaseItem[] { };
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
LibraryManager.RootFolder.Children
|
||||||
|
.OfType<Folder>()
|
||||||
|
.Where(i => i.Path != null && locationsDicionary.ContainsKey(i.Path))
|
||||||
|
.SelectMany(c => c.Children);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetDynamicChildren()
|
||||||
|
{
|
||||||
|
_actualChildren = null;
|
||||||
|
_linkedChildren = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1283,6 +1283,8 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
UpdateItemInLibraryCache(item);
|
UpdateItemInLibraryCache(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCollectionFolders();
|
||||||
|
|
||||||
if (ItemAdded != null)
|
if (ItemAdded != null)
|
||||||
{
|
{
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
|
@ -1336,6 +1338,8 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
public void ReportItemRemoved(BaseItem item)
|
public void ReportItemRemoved(BaseItem item)
|
||||||
{
|
{
|
||||||
|
UpdateCollectionFolders();
|
||||||
|
|
||||||
if (ItemRemoved != null)
|
if (ItemRemoved != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1349,6 +1353,14 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateCollectionFolders()
|
||||||
|
{
|
||||||
|
foreach (var folder in _userManager.Users.SelectMany(i => i.RootFolder.Children).OfType<CollectionFolder>().ToList())
|
||||||
|
{
|
||||||
|
folder.ResetDynamicChildren();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the item.
|
/// Retrieves the item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user