aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs')
-rw-r--r--Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs18
1 files changed, 16 insertions, 2 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
index 1a4c9da41c..4cd02bcd8d 100644
--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
@@ -612,11 +612,12 @@ public sealed partial class BaseItemRepository
var blockedTagItemIds = context.ItemValuesMap
.Where(f => f.ItemValue.Type == ItemValueType.Tags && excludedTags.Contains(f.ItemValue.CleanValue))
.Select(f => f.ItemId);
+ var blockedByAncestor = ItemsBelowTaggedAncestor(context, blockedTagItemIds);
baseQuery = baseQuery.Where(e =>
!blockedTagItemIds.Contains(e.Id)
&& !(e.SeriesId.HasValue && blockedTagItemIds.Contains(e.SeriesId.Value))
- && !e.Parents!.Any(p => blockedTagItemIds.Contains(p.ParentItemId))
+ && !blockedByAncestor.Contains(e.Id)
&& !(e.TopParentId.HasValue && blockedTagItemIds.Contains(e.TopParentId.Value)));
}
@@ -629,10 +630,12 @@ public sealed partial class BaseItemRepository
.Where(f => f.ItemValue.Type == ItemValueType.Tags && includeTags.Contains(f.ItemValue.CleanValue))
.Select(f => f.ItemId);
+ var allowedByAncestor = ItemsBelowTaggedAncestor(context, allowedTagItemIds);
+
baseQuery = baseQuery.Where(e =>
allowedTagItemIds.Contains(e.Id)
|| (e.SeriesId.HasValue && allowedTagItemIds.Contains(e.SeriesId.Value))
- || e.Parents!.Any(p => allowedTagItemIds.Contains(p.ParentItemId))
+ || allowedByAncestor.Contains(e.Id)
|| (e.TopParentId.HasValue && allowedTagItemIds.Contains(e.TopParentId.Value))
// People don't carry the tags of the media they appear in and would never match
@@ -643,6 +646,17 @@ public sealed partial class BaseItemRepository
}
/// <summary>
+ /// Reads back the items that carry one of the tagged items as an ancestor.
+ /// </summary>
+ /// <param name="context">The database context.</param>
+ /// <param name="taggedItemIds">The ids of the items carrying the tag.</param>
+ /// <returns>The ids of the items below one of them.</returns>
+ private static IQueryable<Guid> ItemsBelowTaggedAncestor(JellyfinDbContext context, IQueryable<Guid> taggedItemIds)
+ => context.AncestorIds
+ .Where(a => taggedItemIds.Contains(a.ParentItemId))
+ .Select(a => a.ItemId);
+
+ /// <summary>
/// Builds a filter expression for max parental rating that handles both rated items
/// and unrated BoxSets/Playlists (which check linked children's ratings).
/// </summary>