Skip to content

Performance: Request cache referenced entities when saving documents with block editors#20590

Merged
kjac merged 7 commits intomainfrom
v16/improvement/performance-on-save
Oct 31, 2025
Merged

Performance: Request cache referenced entities when saving documents with block editors#20590
kjac merged 7 commits intomainfrom
v16/improvement/performance-on-save

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Oct 21, 2025

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:

  • Added request cache for content and media references in multi URL picker
  • Added block list "pre-caching" of referenced content and media in media picker and multi URL picker

The latter introduces a new interface that ICacheReferencedEntities property editor DataValueEditors 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 MediaPicker3PropertyEditor you can check that referenced entities are cached and retrieved from the cache when needed.

@AndyButland AndyButland changed the title V16/improvement/performance on save Performance: Request cache referenced entities when saving documents with block editors Oct 21, 2025
@AndyButland AndyButland marked this pull request as ready for review October 22, 2025 14:18
Copilot AI review requested due to automatic review settings October 22, 2025 14:18
Copy link
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 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 ICacheReferencedEntities interface for property editors to implement batch caching of referenced entities
  • Implemented request caching in MultiUrlPickerValueEditor and MediaPicker3PropertyValueEditor for content and media references
  • Added protected helper methods in DataValueEditor base 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

…Editor.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@kjac kjac self-assigned this Oct 30, 2025
@kjac kjac self-requested a review October 30, 2025 07:44
@AndyButland
Copy link
Contributor Author

Checks for availability of request cache have been added @kjac (also reviewed and updated as necessary from the two linked PRs above).

@kjac kjac merged commit 66409b9 into main Oct 31, 2025
24 of 25 checks passed
@kjac kjac deleted the v16/improvement/performance-on-save branch October 31, 2025 09:49
AndyButland added a commit that referenced this pull request Oct 31, 2025
…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>
@AndyButland
Copy link
Contributor Author

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.

@umbraco umbraco deleted a comment from Copilot AI Nov 3, 2025
AndyButland added a commit that referenced this pull request Nov 3, 2025
…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>
@AndyButland
Copy link
Contributor Author

Cherry-picked now too for 17.0.

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/16.4.0 release/17.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants