From 66ac2f46e2e69ebe70c0e8e40e2d9049bdecf033 Mon Sep 17 00:00:00 2001 From: enyineer Date: Sun, 15 Mar 2026 03:13:43 +0100 Subject: [PATCH 1/2] fix: use ParentId per library instead of TopParentIds for mediabar TopParentIds filters on an internal DB column whose values differ from the user-facing view GUIDs returned by getUserViews(). This caused 0 results when specific libraries were selected. Switch to per-library queries using ParentId (which matches view IDs), each with OrderBy=Random and Limit for efficient DB-level random selection without loading entire libraries into memory. Also sets OrderBy=Random via reflection to avoid compile-time reference to SortOrder which moved assemblies between 10.10 and 10.11. --- backend/Api/MoonfinController.cs | 50 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/backend/Api/MoonfinController.cs b/backend/Api/MoonfinController.cs index da69b70..f58bef6 100644 --- a/backend/Api/MoonfinController.cs +++ b/backend/Api/MoonfinController.cs @@ -534,31 +534,49 @@ private static string GetTag(ItemImageInfo info) /// private List GetLibraryItems(List? libraryIds, int limit) { - var query = new InternalItemsQuery + if (libraryIds is not { Count: > 0 }) { - IncludeItemTypes = [BaseItemKind.Movie, BaseItemKind.Series], - Limit = limit, - Recursive = true - }; + // No specific libraries selected — query across all libraries + var query = new InternalItemsQuery + { + IncludeItemTypes = [BaseItemKind.Movie, BaseItemKind.Series], + Limit = limit, + Recursive = true + }; + SetRandomOrder(query); + return _libraryManager.GetItemsResult(query).Items.ToList(); + } - // Set OrderBy = Random via reflection to avoid compile-time reference to - // SortOrder which moved assemblies between Jellyfin 10.10 and 10.11 - SetRandomOrder(query); + // Query each selected library via ParentId (matches user view IDs from getUserViews). + // TopParentIds won't work here — it filters on an internal DB column + // whose values differ from the user-facing view GUIDs. + var allItems = new List(); + var seenIds = new HashSet(); + var perLibraryLimit = Math.Max(1, limit / libraryIds.Count + 1); - if (libraryIds is { Count: > 0 }) + foreach (var libId in libraryIds) { - var parsedIds = libraryIds - .Select(id => Guid.TryParse(id, out var g) ? g : Guid.Empty) - .Where(g => g != Guid.Empty) - .ToArray(); + if (!Guid.TryParse(libId, out var parentGuid)) continue; - if (parsedIds.Length > 0) + var query = new InternalItemsQuery { - query.TopParentIds = parsedIds; + IncludeItemTypes = [BaseItemKind.Movie, BaseItemKind.Series], + ParentId = parentGuid, + Limit = perLibraryLimit, + Recursive = true + }; + SetRandomOrder(query); + + foreach (var item in _libraryManager.GetItemsResult(query).Items) + { + if (seenIds.Add(item.Id)) + { + allItems.Add(item); + } } } - return _libraryManager.GetItemsResult(query).Items.ToList(); + return allItems.Take(limit).ToList(); } /// From c5f292f17d7214c36ff24518ce6cdac39225a722 Mon Sep 17 00:00:00 2001 From: enyineer Date: Sun, 15 Mar 2026 03:13:43 +0100 Subject: [PATCH 2/2] fix: use ParentId per library instead of TopParentIds for mediabar TopParentIds filters on an internal DB column whose values differ from the user-facing view GUIDs returned by getUserViews(). This caused 0 results when specific libraries were selected. Switch to per-library queries using ParentId (which matches view IDs), each with OrderBy=Random and Limit for efficient DB-level random selection without loading entire libraries into memory. Also sets OrderBy=Random via reflection to avoid compile-time reference to SortOrder which moved assemblies between 10.10 and 10.11. --- backend/Api/MoonfinController.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/Api/MoonfinController.cs b/backend/Api/MoonfinController.cs index f58bef6..96caac4 100644 --- a/backend/Api/MoonfinController.cs +++ b/backend/Api/MoonfinController.cs @@ -576,6 +576,13 @@ private List GetLibraryItems(List? libraryIds, int limit) } } + // Shuffle merged results for fair representation across libraries + for (var i = allItems.Count - 1; i > 0; i--) + { + var j = Random.Shared.Next(i + 1); + (allItems[i], allItems[j]) = (allItems[j], allItems[i]); + } + return allItems.Take(limit).ToList(); }