Merge pull request #5808 from cvium/semi-fix-collection-perf

This commit is contained in:
Bond-009 2021-04-21 13:52:51 +02:00 committed by GitHub
commit 48ed4b016c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 27 deletions

View File

@ -121,7 +121,7 @@ namespace Emby.Server.Implementations.Collections
private IEnumerable<BoxSet> GetCollections(User user) private IEnumerable<BoxSet> GetCollections(User user)
{ {
var folder = GetCollectionsFolder(false).Result; var folder = GetCollectionsFolder(false).GetAwaiter().GetResult();
return folder == null return folder == null
? Enumerable.Empty<BoxSet>() ? Enumerable.Empty<BoxSet>()
@ -316,11 +316,11 @@ namespace Emby.Server.Implementations.Collections
{ {
var results = new Dictionary<Guid, BaseItem>(); var results = new Dictionary<Guid, BaseItem>();
var allBoxsets = GetCollections(user).ToList(); var allBoxSets = GetCollections(user).ToList();
foreach (var item in items) foreach (var item in items)
{ {
if (!(item is ISupportsBoxSetGrouping)) if (item is not ISupportsBoxSetGrouping)
{ {
results[item.Id] = item; results[item.Id] = item;
} }
@ -328,24 +328,36 @@ namespace Emby.Server.Implementations.Collections
{ {
var itemId = item.Id; var itemId = item.Id;
var currentBoxSets = allBoxsets var itemIsInBoxSet = false;
.Where(i => i.ContainsLinkedChildByItemId(itemId)) foreach (var boxSet in allBoxSets)
.ToList(); {
if (!boxSet.ContainsLinkedChildByItemId(itemId))
{
continue;
}
if (currentBoxSets.Count > 0) itemIsInBoxSet = true;
{
foreach (var boxset in currentBoxSets) results.TryAdd(boxSet.Id, boxSet);
{
results[boxset.Id] = boxset;
} }
}
else // skip any item that is in a box set
if (itemIsInBoxSet)
{ {
continue;
}
var alreadyInResults = false; var alreadyInResults = false;
foreach (var child in item.GetMediaSources(true)) // this is kind of a performance hack because only Video has alternate versions that should be in a box set?
if (item is Video video)
{ {
if (Guid.TryParse(child.Id, out var id) && results.ContainsKey(id)) foreach (var childId in video.GetLocalAlternateVersionIds())
{ {
if (!results.ContainsKey(childId))
{
continue;
}
alreadyInResults = true; alreadyInResults = true;
break; break;
} }
@ -353,8 +365,7 @@ namespace Emby.Server.Implementations.Collections
if (!alreadyInResults) if (!alreadyInResults)
{ {
results[item.Id] = item; results[itemId] = item;
}
} }
} }
} }

View File

@ -1433,11 +1433,16 @@ namespace MediaBrowser.Controller.Entities
var linkedChildren = LinkedChildren; var linkedChildren = LinkedChildren;
foreach (var i in linkedChildren) foreach (var i in linkedChildren)
{ {
if (i.ItemId.HasValue && i.ItemId.Value == itemId) if (i.ItemId.HasValue)
{
if (i.ItemId.Value == itemId)
{ {
return true; return true;
} }
continue;
}
var child = GetLinkedChild(i); var child = GetLinkedChild(i);
if (child != null && child.Id == itemId) if (child != null && child.Id == itemId)