Optimize accessibility checks

This commit is contained in:
Shadowghost
2026-02-05 19:57:03 +01:00
parent a0346fe5b7
commit 0c46004cd9
2 changed files with 25 additions and 3 deletions

View File

@@ -1350,8 +1350,27 @@ namespace MediaBrowser.Controller.Entities
if (itemCollectionFolders.Count > 0)
{
var userCollectionFolders = LibraryManager.GetUserRootFolder().GetChildren(user, true).Select(i => i.Id).ToList();
if (!itemCollectionFolders.Any(userCollectionFolders.Contains))
var blockedMediaFolders = user.GetPreferenceValues<Guid>(PreferenceKind.BlockedMediaFolders);
IEnumerable<Guid> userCollectionFolderIds;
if (blockedMediaFolders.Length > 0)
{
// User has blocked folders - get all library folders and exclude blocked ones
userCollectionFolderIds = LibraryManager.GetUserRootFolder().Children
.Select(i => i.Id)
.Where(id => !blockedMediaFolders.Contains(id));
}
else if (user.HasPermission(PermissionKind.EnableAllFolders))
{
// User can access all folders - no need to filter
return true;
}
else
{
// User has specific enabled folders
userCollectionFolderIds = user.GetPreferenceValues<Guid>(PreferenceKind.EnabledFolders);
}
if (!itemCollectionFolders.Any(userCollectionFolderIds.Contains))
{
return false;
}

View File

@@ -1699,8 +1699,11 @@ namespace MediaBrowser.Controller.Entities
if (SupportsPlayedStatus || (itemDto is not null && fields.ContainsField(ItemFields.RecursiveItemCount)))
{
// Create a minimal query with just the user - skip ConfigureUserAccess to avoid
// expensive GetUserViews calls. Since we're counting descendants of a specific
// item (this folder) that the user already has access to, TopParentIds filtering
// is redundant. The parental rating filter is applied via query.User.
var query = new InternalItemsQuery(user);
LibraryManager.ConfigureUserAccess(query, user);
int playedCount;
int totalCount;