optimize FindByPath

This commit is contained in:
Luke Pulverenti
2016-03-01 14:39:46 -05:00
parent 177cc41e3d
commit 076a07a546
7 changed files with 40 additions and 2 deletions

View File

@@ -664,7 +664,7 @@ namespace MediaBrowser.Server.Implementations.IO
while (item == null && !string.IsNullOrEmpty(path))
{
item = LibraryManager.RootFolder.FindByPath(path);
item = LibraryManager.FindByPath(path);
path = Path.GetDirectoryName(path);
}

View File

@@ -788,6 +788,23 @@ namespace MediaBrowser.Server.Implementations.Library
return _userRootFolder;
}
public BaseItem FindByPath(string path)
{
var query = new InternalItemsQuery
{
Path = path
};
var items = GetItemIds(query).Select(GetItemById).Where(i => i != null).ToArray();
if (items.Length == 1)
{
return items[0];
}
return RootFolder.FindByPath(path);
}
/// <summary>
/// Gets a Person
/// </summary>

View File

@@ -130,6 +130,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID)",
"create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)",
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
@@ -1804,6 +1805,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = query.ParentId.Value;
}
if (!string.IsNullOrWhiteSpace(query.Path))
{
whereClauses.Add("Path=@Path");
cmd.Parameters.Add(cmd, "@Path", DbType.String).Value = query.Path;
}
if (query.MinEndDate.HasValue)
{
whereClauses.Add("EndDate>=@MinEndDate");