perf: Bulk load option set options and restore entity cache [DHIS2-21905] - #25003
Draft
netroms wants to merge 1 commit into
Draft
perf: Bulk load option set options and restore entity cache [DHIS2-21905]#25003netroms wants to merge 1 commit into
netroms wants to merge 1 commit into
Conversation
…905] Nested options on /api/optionSets loaded one collection per option set, and query-cache hits re-selected every OptionSet row because the entity-level cache was lost in the OptionSet.hbm.xml to JPA migration. - Restore the OptionSet entity L2 cache with an explicit ehcache region - Preload requested options collections with one cache-aware fetch-join query - Skip the preload entirely when the requested fields omit options
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
GET /api/optionSetswith nestedoptions[...]fields executes oneoptionvalueselect per option set in the page (100 sets = 100 selects in the DHIS2-21905 capture), and on a Hibernate query-cache hit additionally re-selects everyOptionSetrow by id because the entity lost its L2 cache in theOptionSet.hbm.xmlto JPA migration (fa6a855).OptionSetentity L2 cache (NONSTRICT_READ_WRITE) with an explicit store-by-reference ehcache region (20k entries, 1h TTL), so query-cache hits resolve entities from L2 instead of PostgreSQLOptionSetStore.preloadOptions(...): one non-cacheable fetch-join query bulk-loads the options collections absent from the collection cache; warm collections initialize from L2 without SQLOptionSetControllerinvokes the preload only when the expanded field paths includeoptions, so requests without options never load themResulting SQL shape for a nested-options list request: cold = parent page query + 1 bulk options query, warm = 0 option queries.
Testing
HibernateQueryCacheTest: a query-cache hit in a fresh persistence context must not reloadOptionSetfrom PostgreSQL (failed with one select per id before the fix)HibernateEhcacheConfigFileTest: pins the explicitOptionSetregion and its heap boundOptionSetControllerQueryCountTest(Postgres, committed fixtures, real L2): cold nested request uses exactly oneoptionvaluestatement, warm request zero,fieldswithout options load nothing, and committed option scalar updates plus add/remove/reorder are visible on the next requestAI Assisted