Skip to content

Management API: Optimize collection view performance by eliminating N+1 patterns#21684

Merged
nikolajlauridsen merged 12 commits intomainfrom
v17/improvement/further-collection-view-optimisations
Feb 12, 2026
Merged

Management API: Optimize collection view performance by eliminating N+1 patterns#21684
nikolajlauridsen merged 12 commits intomainfrom
v17/improvement/further-collection-view-optimisations

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Feb 9, 2026

Summary

Eliminates multiple N+1 query patterns in the collection view (list view) pipeline. Each optimization replaces per-item service calls with single batched operations. These will often be returning cached data, but nevertheless, there's some overhead regarding scopes we can avoid even in these cases:

  • Permissions: Replaced per-item GetPermissionsForPath with a single batch GetPermissions call across all unique path node IDs.
  • IsProtected: Replaced per-item IsProtected calls with a single GetAll() query + in-memory path matching.
  • GetPathKeys: Computes ancestor path keys once for collection siblings (shared parent) instead of per item.
  • Schedule flags: Eliminated redundant GUID-to-int conversions in HasScheduleFlagProvider.
  • User profiles: Pre-resolves all unique Creator/Writer names via a single GetUsersById batch call and passes them through MapperContext, replacing per-item GetProfileById calls.

Impact

Once these were in place, with a setup using a collection view over a document set of 10000+ items, I could see significant improvements. This will vary depending on factors such as database latency, hardware etc., but in my tests there was a ~23% measured improvement in response time for content collection API requests.

Testing

Verify collection view render as before, including the filtering out of documents that the user doesn't have permission to see.

Copilot AI review requested due to automatic review settings February 9, 2026 10:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets the Management API “collection view” pipeline, removing several N+1-style per-item service calls by switching to batched lookups and by passing pre-resolved data through MapperContext.Items during mapping.

Changes:

  • Batch-resolve creator/writer display names and inject them into mapping via MapperContext to avoid per-item GetProfileById calls.
  • Replace schedule flag population to use a key-keyed schedule lookup (GetContentSchedulesByKeys) and obsolete the old id-keyed API.
  • Optimize permission filtering by batching permission retrieval across all unique node IDs in the paths being authorized.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Umbraco.Cms.Api.Management/Factories/ContentCollectionPresentationFactory.cs Adds batched user-name resolution and passes it through MapperContext.
src/Umbraco.Core/Models/Mapping/MapperContextExtensions.cs Adds Get/SetUserNameDictionary helpers for mapper context items.
src/Umbraco.Core/Models/Mapping/CommonMapper.cs Uses context-provided user-name dictionary with service fallback.
src/Umbraco.Cms.Api.Management/Factories/DocumentCollectionPresentationFactory.cs Batches public access protection checks and reuses shared ancestors for collection siblings.
src/Umbraco.Core/Services/ContentPermissionService.cs Reworks authorization filtering to batch permissions lookup across paths.
src/Umbraco.Core/Services/IContentService.cs Marks GetContentSchedulesByIds obsolete and introduces GetContentSchedulesByKeys.
src/Umbraco.Core/Services/ContentService.cs Implements GetContentSchedulesByKeys and adapts obsolete ...ByIds to call it.
src/Umbraco.Cms.Api.Management/Services/Flags/HasScheduleFlagProvider.cs Switches schedule lookup to the new key-keyed API.
src/Umbraco.Cms.Api.Management/Factories/MediaCollectionPresentationFactory.cs Adds DI constructor overload to supply IUserService to the base factory.
tests/Umbraco.Tests.UnitTests/.../CommonMapperTests.cs New tests covering dictionary-first name mapping with fallback behavior.
tests/Umbraco.Tests.UnitTests/.../DocumentCollectionPresentationFactoryTests.cs New tests for batched protection, shared ancestors, and batched user lookup behavior.
tests/Umbraco.Tests.UnitTests/.../HasScheduleFlagProviderTests.cs Updates tests for key-keyed schedule lookup.
tests/Umbraco.Tests.Integration/.../ContentListViewServiceTests.cs Updates list view integration tests and adds browse-permission filtering coverage.
tests/Umbraco.Tests.Integration/.../ContentServiceTests.cs Splits schedule tests into obsolete-ids and new-keys variants.

Copy link
Copy Markdown
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small points, otherwise looks good to me 👍

Copy link
Copy Markdown
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category/performance Fixes for performance (generally cpu or memory) fixes release/17.3.0 type/improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants