fix: only generate links when fields expand to href [DHIS2-21856] (2.43)#24501
Merged
Conversation
Single-object GET treated any field preset (e.g. :owner) as if href was requested, triggering deep link generation that reflectively initializes every lazy collection of the entity. On objects with very large collections (e.g. a user role with 240k members) this loads and L2-caches every member entity, taking 30+ seconds of CPU per request. Only *, :all and :simple actually expand to the transient href property, so only those (and a literal href field) now trigger link generation. Response payloads are unchanged for all field values. AI Assisted
netroms
force-pushed
the
DHIS2-fix-href-preset-2.43
branch
from
July 19, 2026 12:26
e3394f7 to
7dd3fdb
Compare
netroms
marked this pull request as ready for review
July 19, 2026 12:26
|
jbee
approved these changes
Jul 20, 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.



Fix: only generate links when fields expand to href
Problem
A production Glowroot trace showed
GET /api/userRoles/{id}?fields=:owner,access,displayName,authoritiestaking 33s wall / 31s CPU / 17.5 GB allocated.AbstractFullReadOnlyControllertreats any field preset (:owner,:identifiable, ...) as ifhrefwas requested. This triggersLinkService.generateLinks(..., deep=true), which reflectively invokes every IdentifiableObject getter on the entity - initializing every lazy collection. For a user role with ~241k members this loads all memberUserentities and pushes each one through the serializing L2 cache copier, then throws the result away (:ownernever serializeshref).Fix
Only
*,:alland:simplepresets actually expand to the transienthrefproperty, so only those (plus a literalhreffield, incl. nested likeusers[href]) now trigger link generation. Everything that previously returnedhrefstill returns it - response payloads are unchanged for all field values.Note: master got an equivalent (stricter) heuristic via #24011; this is a minimal standalone backport that additionally preserves the
:simpleand nested-href triggers.Verification
New parameterized tests in
AbstractCrudControllerTestasserthrefpresence for:all,*,:simple,href,id,href,id,name,hrefand absence for:owner,:identifiable,:nameable,:persisted,id,name(13/13 pass, H2).AI Assisted