diff options
| author | Bond-009 <bond.009@outlook.com> | 2021-04-21 13:52:51 +0200 |
|---|---|---|
| committer | Joshua M. Boniface <joshua@boniface.me> | 2021-04-21 21:24:27 -0400 |
| commit | fcb729ff6b9fb20bf395d9acd7a22d79c44c0713 (patch) | |
| tree | 95695a6d5a6997df83a2ee6984a972164482e718 | |
| parent | 69f30bc52cf013a6d421287e13789a8b78d9c487 (diff) | |
Merge pull request #5808 from cvium/semi-fix-collection-perf
(cherry picked from commit 48ed4b016c43cdb9b18f864a031b5b652a88904a)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
| -rw-r--r-- | Emby.Server.Implementations/Collections/CollectionManager.cs | 51 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Folder.cs | 9 |
2 files changed, 38 insertions, 22 deletions
diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index db532ce5b..81758d9a7 100644 --- a/Emby.Server.Implementations/Collections/CollectionManager.cs +++ b/Emby.Server.Implementations/Collections/CollectionManager.cs @@ -124,7 +124,7 @@ namespace Emby.Server.Implementations.Collections private IEnumerable<BoxSet> GetCollections(User user) { - var folder = GetCollectionsFolder(false).Result; + var folder = GetCollectionsFolder(false).GetAwaiter().GetResult(); return folder == null ? Enumerable.Empty<BoxSet>() @@ -319,11 +319,11 @@ namespace Emby.Server.Implementations.Collections { var results = new Dictionary<Guid, BaseItem>(); - var allBoxsets = GetCollections(user).ToList(); + var allBoxSets = GetCollections(user).ToList(); foreach (var item in items) { - if (!(item is ISupportsBoxSetGrouping)) + if (item is not ISupportsBoxSetGrouping) { results[item.Id] = item; } @@ -331,34 +331,45 @@ namespace Emby.Server.Implementations.Collections { var itemId = item.Id; - var currentBoxSets = allBoxsets - .Where(i => i.ContainsLinkedChildByItemId(itemId)) - .ToList(); - - if (currentBoxSets.Count > 0) + var itemIsInBoxSet = false; + foreach (var boxSet in allBoxSets) { - foreach (var boxset in currentBoxSets) + if (!boxSet.ContainsLinkedChildByItemId(itemId)) { - results[boxset.Id] = boxset; + continue; } + + itemIsInBoxSet = true; + + results.TryAdd(boxSet.Id, boxSet); + } + + // skip any item that is in a box set + if (itemIsInBoxSet) + { + continue; } - else + + var alreadyInResults = false; + // 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) { - var alreadyInResults = false; - foreach (var child in item.GetMediaSources(true)) + foreach (var childId in video.GetLocalAlternateVersionIds()) { - if (Guid.TryParse(child.Id, out var id) && results.ContainsKey(id)) + if (!results.ContainsKey(childId)) { - alreadyInResults = true; - break; + continue; } - } - if (!alreadyInResults) - { - results[item.Id] = item; + alreadyInResults = true; + break; } } + + if (!alreadyInResults) + { + results[itemId] = item; + } } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index cac5026f7..bd1fbb473 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1434,9 +1434,14 @@ namespace MediaBrowser.Controller.Entities var linkedChildren = LinkedChildren; foreach (var i in linkedChildren) { - if (i.ItemId.HasValue && i.ItemId.Value == itemId) + if (i.ItemId.HasValue) { - return true; + if (i.ItemId.Value == itemId) + { + return true; + } + + continue; } var child = GetLinkedChild(i); |
