-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Performance: Use request cache for ContentSourceDto retrieval
#21282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 adds request-level caching to the DatabaseCacheRepository to optimize redundant database queries for ContentSourceDto lookups within a single HTTP request. The implementation caches the DTO object (which contains both draft and published data) and reuses it for multiple calls with different preview parameters, since the preview flag only determines which data fields to use from the DTO.
Key changes:
- Extracts database lookup logic into a new private
GetContentSourceDtomethod with request-level caching - Extracts ContentCacheNode creation logic into a new private
CreateContentCacheNodemethod for better separation of concerns - Updates XML documentation to clarify that the
previewparameter affects the returned data
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Umbraco.PublishedCache.HybridCache/Persistence/IDatabaseCacheRepository.cs | Updates XML documentation to clarify that GetContentSourceAsync considers both document key and preview status |
| src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs | Adds request-level caching for ContentSourceDto retrieval and refactors GetContentSourceAsync into three focused methods |
…e and we are retrieving a value we know hasn't been updated since the last request.
804e701 to
bff162f
Compare
ContentSourceDto retrieval
|
Just looking at this, it seems there is only one place where we call the |
|
They do to an extent - however I don't think it's quite as simple as that, as the problem is we have the repository responsible for populating So it seemed to me the only way to move the cache to the service - which I agree is the best place - is to have the repository return That was the crux of my point here:
If you can see a way to unpick that problem in a clean way, I'd appreciate the attempt or suggestion. |
|
Fair point, I don't have any other good ideas, but as you say it just doesn't feel right 🙈 |
|
I haven't merged this as it was still nagging me that there should be a cleaner approach, which I think I've found in #21407. So will close this and propose the other in preference. |
|
Agreed, much cleaner 😁 |
Description
It was noted that
GetContentSourceAsyncis called more than once during save and publish operations, and that we go to the database both for published and draft content even though the data returned is the same. This PR adds a request cache around this, ensuring we only request the underlying DTO once, and then create theContentCacheNodeas appropriate from that.Not super-happy with the implementation here - it seemed I either needed to pass a parameter indicating whether to use the cache, or have the repository expose the
ContentSourceDtoso the service can decide whether to re-get it or not. Neither felt very nice, but I've gone with the former. Maybe reviewers have a better approach here.Change Summary
ContentSourceDtolookups inDatabaseCacheRepositoryto avoid redundant database queries within the same HTTP requestGetContentSourceAsyncby extractingGetContentSourceDto(with caching) andCreateContentCacheNodemethodspreviewparameterTesting
Via a breakpoint you can verify that during a save and publish operation, only the first request for a content cache node hits the database.