Skip to content

fix: only generate links when fields expand to href [DHIS2-21856] (2.43)#24501

Merged
jason-p-pickering merged 1 commit into
2.43from
DHIS2-fix-href-preset-2.43
Jul 20, 2026
Merged

fix: only generate links when fields expand to href [DHIS2-21856] (2.43)#24501
jason-p-pickering merged 1 commit into
2.43from
DHIS2-fix-href-preset-2.43

Conversation

@netroms

@netroms netroms commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fix: only generate links when fields expand to href

Problem

A production Glowroot trace showed GET /api/userRoles/{id}?fields=:owner,access,displayName,authorities taking 33s wall / 31s CPU / 17.5 GB allocated.

AbstractFullReadOnlyController treats any field preset (:owner, :identifiable, ...) as if href was requested. This triggers LinkService.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 member User entities and pushes each one through the serializing L2 cache copier, then throws the result away (:owner never serializes href).

Fix

Only *, :all and :simple presets actually expand to the transient href property, so only those (plus a literal href field, incl. nested like users[href]) now trigger link generation. Everything that previously returned href still 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 :simple and nested-href triggers.

Verification

New parameterized tests in AbstractCrudControllerTest assert href presence for :all, *, :simple, href, id,href, id,name,href and absence for :owner, :identifiable, :nameable, :persisted, id,name (13/13 pass, H2).

AI Assisted

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
netroms force-pushed the DHIS2-fix-href-preset-2.43 branch from e3394f7 to 7dd3fdb Compare July 19, 2026 12:26
@netroms netroms changed the title fix: only generate links when fields expand to href (2.43) fix: only generate links when fields expand to href [DHIS2-21856] (2.43) Jul 19, 2026
@netroms
netroms marked this pull request as ready for review July 19, 2026 12:26
@sonarqubecloud

Copy link
Copy Markdown

@jason-p-pickering
jason-p-pickering merged commit deaba3c into 2.43 Jul 20, 2026
18 checks passed
@jason-p-pickering
jason-p-pickering deleted the DHIS2-fix-href-preset-2.43 branch July 20, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants