Management API: Optimize collection view performance by eliminating N+1 patterns#21684
Merged
nikolajlauridsen merged 12 commits intomainfrom Feb 12, 2026
Merged
Conversation
…ermissions query across all unique path node ids.
…ixed constructors.
… and in-memory path matching. Compute shared ancestor path keys once for collection siblings instead of per item.
Contributor
There was a problem hiding this comment.
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
MapperContextto avoid per-itemGetProfileByIdcalls. - 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. |
src/Umbraco.Cms.Api.Management/Factories/ContentCollectionPresentationFactory.cs
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Management/Factories/DocumentCollectionPresentationFactory.cs
Show resolved
Hide resolved
Contributor
nikolajlauridsen
left a comment
There was a problem hiding this comment.
A few small points, otherwise looks good to me 👍
src/Umbraco.Cms.Api.Management/Factories/DocumentCollectionPresentationFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Management/Factories/DocumentCollectionPresentationFactory.cs
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Management/Factories/MediaCollectionPresentationFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Management/Services/Flags/HasScheduleFlagProvider.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Management/Services/Flags/HasScheduleFlagProvider.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
This was referenced Apr 2, 2026
This was referenced Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
GetPermissionsForPathwith a single batchGetPermissionscall across all unique path node IDs.IsProtectedcalls with a singleGetAll()query + in-memory path matching.HasScheduleFlagProvider.GetUsersByIdbatch call and passes them throughMapperContext, replacing per-itemGetProfileByIdcalls.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.