aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
authorbrandon <brandon@clinger.dev>2026-08-08 12:33:11 -0400
committerbrandon <brandon@clinger.dev>2026-08-08 12:33:11 -0400
commit10d108a1f453c0972b3059e10bb9b13bbcb34f63 (patch)
treeb00f02ff96a21a78b35ca69ef5614466e0afc3ca /Emby.Server.Implementations
parentc091ffdc6b2d8d4dd6f439d056c561bae7bd9a18 (diff)
Address review on MediaSourceCount batching
Rename GetItemsWithAlternateVersions to GetItemIdsWithAlternateVersions across the interfaces and implementations since it returns ids. Return the hashset straight from the query instead of materializing an array first. Rename the DtoService guard to mayHaveAlternateVersions and invert it so the computed path is the explicit case. Assert the media source count value in the batch skip test and add a test covering an item that is in the returned set still resolving to the correct count.
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/Dto/DtoService.cs18
-rw-r--r--Emby.Server.Implementations/Library/LibraryManager.cs4
2 files changed, 12 insertions, 10 deletions
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index 062c19a1d4..6fa057702c 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -261,7 +261,7 @@ namespace Emby.Server.Implementations.Dto
var versionItemIds = accessibleItems.OfType<Video>().Select(i => i.Id).ToList();
if (versionItemIds.Count > 0)
{
- alternateVersionItemIds = _libraryManager.GetItemsWithAlternateVersions(versionItemIds);
+ alternateVersionItemIds = _libraryManager.GetItemIdsWithAlternateVersions(versionItemIds);
}
}
@@ -1314,13 +1314,15 @@ namespace Emby.Server.Implementations.Dto
if (options.ContainsField(ItemFields.MediaSourceCount))
{
// A video with no primary version and no alternate versions always has a single
- // media source. When the batch has already determined this item owns no alternate
- // versions, skip the per-item alternate-version queries entirely (the common case).
- var hasNoAlternateVersions = alternateVersionItemIds is not null
- && !video.PrimaryVersionId.HasValue
- && !alternateVersionItemIds.Contains(video.Id);
-
- if (!hasNoAlternateVersions)
+ // media source. Only compute the count for videos that might have more: a primary
+ // version, or membership in the batch's set of items that own alternate versions.
+ // Without the batch we can't rule it out, so fall back to computing (the single-item
+ // path). Everything else is the common case and keeps the default count of one.
+ var mayHaveAlternateVersions = alternateVersionItemIds is null
+ || video.PrimaryVersionId.HasValue
+ || alternateVersionItemIds.Contains(video.Id);
+
+ if (mayHaveAlternateVersions)
{
// Match the per-user filtering of the media sources: versions the user cannot
// access are not selectable, so they must not count towards the badge either.
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs
index 9bb962c504..0c7c411d0c 100644
--- a/Emby.Server.Implementations/Library/LibraryManager.cs
+++ b/Emby.Server.Implementations/Library/LibraryManager.cs
@@ -2235,9 +2235,9 @@ namespace Emby.Server.Implementations.Library
}
/// <inheritdoc />
- public IReadOnlySet<Guid> GetItemsWithAlternateVersions(IReadOnlyList<Guid> itemIds)
+ public IReadOnlySet<Guid> GetItemIdsWithAlternateVersions(IReadOnlyList<Guid> itemIds)
{
- return _linkedChildrenService.GetItemsWithAlternateVersions(itemIds);
+ return _linkedChildrenService.GetItemIdsWithAlternateVersions(itemIds);
}
/// <inheritdoc />