Performance: Request cache referenced entities when saving documents with block editors#20590
Performance: Request cache referenced entities when saving documents with block editors#20590
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves save and publish performance for Umbraco instances with extensive block editor usage by implementing a request caching strategy for referenced entities. The changes introduce a new ICacheReferencedEntities interface that property editors can implement to batch-fetch and cache referenced content and media items in a single database operation, reducing redundant lookups during save operations.
Key changes:
- Added
ICacheReferencedEntitiesinterface for property editors to implement batch caching of referenced entities - Implemented request caching in
MultiUrlPickerValueEditorandMediaPicker3PropertyValueEditorfor content and media references - Added protected helper methods in
DataValueEditorbase class for cached entity retrieval
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Umbraco.Core/PropertyEditors/ICacheReferencedEntities.cs | New interface defining contract for batch caching of referenced entities in block values |
| src/Umbraco.Core/PropertyEditors/DataValueEditor.cs | Added protected helper methods for cached content/media retrieval and cache presence checking |
| src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyValueEditorBase.cs | Added method to invoke entity caching for all property values within block editor data |
| src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyValueEditor.cs | Integrated entity caching invocation before processing block editor values |
| src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs | Implemented ICacheReferencedEntities interface and migrated to shared caching helpers |
| src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs | Implemented ICacheReferencedEntities interface and added request caching for content/media lookups |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/MultiUrlPickerValueEditorValidationTests.cs | Updated test to provide required AppCaches parameter for new constructor |
src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs
Outdated
Show resolved
Hide resolved
…Editor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Checks for availability of request cache have been added @kjac (also reviewed and updated as necessary from the two linked PRs above). |
…with block editors (#20590) * Added request cache to content and media lookups in mult URL picker. * Allow property editors to cache referenced entities from block data. * Update src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add obsoletions. * Minor spellcheck * Ensure request cache is available before relying on it. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
|
Have cherry-picked this and labelled for 16.4. Let's discuss on Monday whether this will also go in 17.0 or 17.1. |
…with block editors (#20590) * Added request cache to content and media lookups in mult URL picker. * Allow property editors to cache referenced entities from block data. * Update src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add obsoletions. * Minor spellcheck * Ensure request cache is available before relying on it. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
|
Cherry-picked now too for 17.0. |
Description
This PR is part of ongoing efforts to improve validation, save and publish time for Umbraco setups using lots of blocks and languages. There are two updates related to save here:
The latter introduces a new interface that
ICacheReferencedEntitiesproperty editorDataValueEditors can optionally implement. If they do, they can parse the provided list of values from a block editor that they know how to handle, to in one go get all the referenced entities they need. They can then make one database request to get and cache them in the request cache, such that they are available later when needed in the save process.In my artificially throttled test setup - using a database from a site with lots of blocks and languages, hosted in Azure whilst I'm working locally - I'm seeing 200% improvements for the save operation when triggered from the backoffice or management API.
To caveat, the publish part still takes quite some time - but this, plus the previous PRs that focussed on the validate and publish steps - #20405 and #20485 - should produce some noticeable improvement.
Testing
Verify content save operations continue to work. Using breakpoints e.g. in
MediaPicker3PropertyEditoryou can check that referenced entities are cached and retrieved from the cache when needed.