perf: avoid loading org unit group members for OUG{} indicator counts (2.42.5.1)#24402
Open
enricocolasante wants to merge 1 commit into
Open
perf: avoid loading org unit group members for OUG{} indicator counts (2.42.5.1)#24402enricocolasante wants to merge 1 commit into
enricocolasante wants to merge 1 commit into
Conversation
…#24260) * perf: avoid loading org unit group members for OUG{} indicator counts substituteIndicatorExpressions (called on every dhis-web-dataentry getMetaData request) resolved each OUG{uid} indicator reference via group.getMembers().size(), which initialises the entire org unit group members collection - on a large instance, 70k+ OrganisationUnit entities hydrated into the session per request. This dominated getMetaData: a ~5s floor and spikes to 14-22s, from the members load, a single-OU rehydration N+1 when the entity cache was cold, and commit-time dirty-checking of the hydrated entities (~2GB allocated per request). Measured floor on a large production instance dropped from ~5.2s to ~0.2s. Resolve the count with a count subquery instead: new OrganisationUnitGroupStore.getOrganisationUnitGroupMemberCounts(uids) uses HQL size(g.members), which never initialises the collection; substituteIndicatorExpressions looks up only the referenced groups and substitutes counts directly. Also mark substituteIndicatorExpressions @transactional(readOnly = true): it only mutates the transient Indicator.exploded* display fields, so it never writes; readOnly sets flush mode MANUAL as a guard against dirty-checking. Behaviour preserved: the count is the global group membership total, as before. The runtime, org-unit-scoped OUG{} count used in analytics is a separate path via orgUnitCountMap. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: assert OUG{} substitution output is unchanged end-to-end Integration test exercising the real substituteIndicatorExpressions against Postgres: asserts the exploded numerator/denominator equal String.valueOf(group.getMembers().size()) - i.e. byte-identical to the pre-change behaviour - while the count now comes from the count query. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor: address SonarQube smells in OUG count fix - collect referenced org unit group UIDs with a stream instead of a separate loop, leaving a single loop over indicators (keeps the single batched count query) - drop redundant Mockito eq() matcher in the substitution unit test Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: reword OUG count comment to avoid SonarQube commented-code false positive java:S125 flagged the explanatory comment as commented-out code because it contained code-like tokens (method-call and brace syntax). Reworded as plain prose; no behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Backport of #24260