diff options
| author | cvium <clausvium@gmail.com> | 2021-04-13 15:37:11 +0200 |
|---|---|---|
| committer | cvium <clausvium@gmail.com> | 2021-04-13 15:38:13 +0200 |
| commit | 723b6abcb392b1a65e46db91aa35f7e13de0c2a8 (patch) | |
| tree | 5e84fb7780f9d47b05b79618c120986d6af4d4bc /Emby.Server.Implementations/Collections | |
| parent | 89ae336694dea14e2b4486b824efde9f1d535e7c (diff) | |
Optimize the way items are grouped into collections
Diffstat (limited to 'Emby.Server.Implementations/Collections')
| -rw-r--r-- | Emby.Server.Implementations/Collections/CollectionManager.cs | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index db532ce5b..6dbbd5530 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,50 @@ 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)) + { + continue; + } + + itemIsInBoxSet = true; + + if (results.ContainsKey(boxSet.Id)) { - results[boxset.Id] = boxset; + continue; } + + results[boxSet.Id] = boxSet; } - else + + // skip any item that is in a box set + if (itemIsInBoxSet) { - var alreadyInResults = false; - foreach (var child in item.GetMediaSources(true)) + continue; + } + + 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) + { + 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[item.Id] = item; + } } } |
