perf: batch-fetch ProgramRule.programRuleActions to avoid per-rule N+1 - #24809
Draft
jason-p-pickering wants to merge 3 commits into
Draft
perf: batch-fetch ProgramRule.programRuleActions to avoid per-rule N+1#24809jason-p-pickering wants to merge 3 commits into
jason-p-pickering wants to merge 3 commits into
Conversation
Mapping ProgramRules to rule-engine Rules (DefaultProgramRuleEntityMapperService.toMappedProgramRules) lazily initializes the programRuleActions collection once per distinct ProgramRule it maps. Live-traced as ~400 single-row "WHERE programruleid = ?" SELECTs in one request. The L2 collection cache doesn't help here since each rule is a first-touch within the request, not a repeat lookup of the same rule. batch-size="100" on the collection folds pending collection initializations within one session into WHERE programruleid IN (...) batches instead, same category as the existing CategoryOption/Option batch-size="100" precedent in this codebase. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
XML comments can't contain a literal '--' anywhere in their content (only as the closing '-->'). This one would have broken Hibernate's HBM XML parsing on startup exactly like the earlier OptionSet/Option incident (625b026): "String '--' not allowed in comment (missing '>'?)", failing entityManagerFactory bean creation and the whole webapp context startup. Replaced with a comma. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
jason-p-pickering
marked this pull request as draft
August 10, 2026 19:28
|
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.



Summary
ProgramRules to rule-engineRules (DefaultProgramRuleEntityMapperService.toMappedProgramRules) lazily initializes theprogramRuleActionscollection once per distinctProgramRuleit maps.SELECT ... FROM programruleaction WHERE programruleid = ?statements in one request (403 executions, ~1 row each) — each is a different rule, so the existing L2 collection cache (nonstrict-read-write/read-write) can't help: it only serves repeat lookups of the same rule's actions, not 403 distinct first-touches within one request.batch-size="100"on theprogramRuleActions<set>folds pending collection initializations within one Hibernate session intoWHERE programruleid IN (...)batches instead, cutting ~400 round trips down to ~5.CategoryOption/Optionbatch-size="100"precedent already in this codebase (ProgramRuleActioninheritsBaseIdentifiableObject's UID-basedequals/hashCode, no mutable-collection risk factor).Test plan
mvn -pl dhis-services/dhis-service-core -am install -DskipTests— clean buildmvn spotless:check— passesprogramruleactionquery count drops from ~400 individual SELECTs to ~5IN (...)batches🤖 AI Assisted