update FindByPath

This commit is contained in:
Luke Pulverenti 2016-05-10 14:43:17 -04:00
parent 5dbf0ddb93
commit 3dc494c02d
2 changed files with 7 additions and 42 deletions

View File

@ -1571,35 +1571,6 @@ namespace MediaBrowser.Controller.Entities
await Task.WhenAll(tasks).ConfigureAwait(false); await Task.WhenAll(tasks).ConfigureAwait(false);
} }
/// <summary>
/// Finds an item by path, recursively
/// </summary>
/// <param name="path">The path.</param>
/// <returns>BaseItem.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public BaseItem FindByPath(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException();
}
if (string.Equals(Path, path, StringComparison.OrdinalIgnoreCase))
{
return this;
}
if (PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase))
{
return this;
}
return GetRecursiveChildren(i => string.Equals(i.Path, path, StringComparison.OrdinalIgnoreCase) ||
(!i.IsFolder && !i.IsInMixedFolder && string.Equals(i.ContainingFolderPath, path, StringComparison.OrdinalIgnoreCase)) ||
i.PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase))
.FirstOrDefault();
}
public override bool IsPlayed(User user) public override bool IsPlayed(User user)
{ {
var itemsResult = GetItems(new InternalItemsQuery(user) var itemsResult = GetItems(new InternalItemsQuery(user)

View File

@ -787,20 +787,14 @@ namespace MediaBrowser.Server.Implementations.Library
IsFolder = isFolder IsFolder = isFolder
}; };
// Only use the database result if there's exactly one item, otherwise we run the risk of returning old data that hasn't been cleaned yet. // If this returns multiple items it could be tricky figuring out which one is correct.
var items = GetItemIds(query).Select(GetItemById).Where(i => i != null).ToArray(); // In most cases, the newest one will be and the others obsolete but not yet cleaned up
if (items.Length == 1) return GetItemIds(query)
{ .Select(GetItemById)
return items[0]; .Where(i => i != null)
} .OrderByDescending(i => i.DateCreated)
.FirstOrDefault();
if (items.Length == 0)
{
return null;
}
return RootFolder.FindByPath(path);
} }
/// <summary> /// <summary>