mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-17 15:53:42 +01:00
reduce library queries
This commit is contained in:
@@ -339,11 +339,6 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
RegisterItem(item.Id, item);
|
||||
}
|
||||
|
||||
private void RegisterItem(Guid id, BaseItem item)
|
||||
{
|
||||
if (item is IItemByName)
|
||||
{
|
||||
if (!(item is MusicArtist))
|
||||
@@ -354,13 +349,13 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
if (item.IsFolder)
|
||||
{
|
||||
if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel) && !(item is AggregateFolder))
|
||||
{
|
||||
if (item.SourceType != SourceType.Library)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
//if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel) && !(item is AggregateFolder))
|
||||
//{
|
||||
// if (item.SourceType != SourceType.Library)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -370,7 +365,7 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
|
||||
LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; });
|
||||
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
|
||||
}
|
||||
|
||||
public async Task DeleteItem(BaseItem item, DeleteOptions options)
|
||||
@@ -822,7 +817,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
return _userRootFolder;
|
||||
}
|
||||
|
||||
|
||||
public BaseItem FindByPath(string path, bool? isFolder)
|
||||
{
|
||||
// If this returns multiple items it could be tricky figuring out which one is correct.
|
||||
@@ -836,7 +831,7 @@ namespace Emby.Server.Implementations.Library
|
||||
SortOrder = SortOrder.Descending,
|
||||
Limit = 1
|
||||
};
|
||||
|
||||
|
||||
return GetItemList(query)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
@@ -1273,10 +1268,8 @@ namespace Emby.Server.Implementations.Library
|
||||
return ItemRepository.GetItemList(query);
|
||||
}
|
||||
|
||||
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query, IEnumerable<string> parentIds)
|
||||
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query, List<BaseItem> parents)
|
||||
{
|
||||
var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList();
|
||||
|
||||
SetTopParentIdsOrAncestors(query, parents);
|
||||
|
||||
if (query.AncestorIds.Length == 0 && query.TopParentIds.Length == 0)
|
||||
@@ -1536,7 +1529,7 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
|
||||
// Handle grouping
|
||||
if (user != null && !string.IsNullOrWhiteSpace(view.ViewType) && UserView.IsEligibleForGrouping(view.ViewType))
|
||||
if (user != null && !string.IsNullOrWhiteSpace(view.ViewType) && UserView.IsEligibleForGrouping(view.ViewType) && user.Configuration.GroupedFolders.Length > 0)
|
||||
{
|
||||
return user.RootFolder
|
||||
.GetChildren(user, true)
|
||||
|
||||
@@ -245,20 +245,26 @@ namespace Emby.Server.Implementations.Library
|
||||
var includeItemTypes = request.IncludeItemTypes;
|
||||
var limit = request.Limit ?? 10;
|
||||
|
||||
var parentIds = string.IsNullOrEmpty(parentId)
|
||||
? new string[] { }
|
||||
: new[] { parentId };
|
||||
var parents = new List<BaseItem>();
|
||||
|
||||
if (parentIds.Length == 0)
|
||||
if (!string.IsNullOrWhiteSpace(parentId))
|
||||
{
|
||||
parentIds = user.RootFolder.GetChildren(user, true)
|
||||
.OfType<Folder>()
|
||||
.Select(i => i.Id.ToString("N"))
|
||||
.Where(i => !user.Configuration.LatestItemsExcludes.Contains(i))
|
||||
.ToArray();
|
||||
var parent = _libraryManager.GetItemById(parentId) as Folder;
|
||||
if (parent != null)
|
||||
{
|
||||
parents.Add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
if (parentIds.Length == 0)
|
||||
if (parents.Count == 0)
|
||||
{
|
||||
parents = user.RootFolder.GetChildren(user, true)
|
||||
.Where(i => i is Folder)
|
||||
.Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N")))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (parents.Count == 0)
|
||||
{
|
||||
return new List<BaseItem>();
|
||||
}
|
||||
@@ -283,10 +289,10 @@ namespace Emby.Server.Implementations.Library
|
||||
ExcludeItemTypes = excludeItemTypes,
|
||||
ExcludeLocationTypes = new[] { LocationType.Virtual },
|
||||
Limit = limit * 5,
|
||||
SourceTypes = parentIds.Length == 0 ? new[] { SourceType.Library } : new SourceType[] { },
|
||||
SourceTypes = parents.Count == 0 ? new[] { SourceType.Library } : new SourceType[] { },
|
||||
IsPlayed = request.IsPlayed
|
||||
|
||||
}, parentIds);
|
||||
}, parents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user