perf: replace /dataEntry/metadata with flat per-type requests [DHIS2-…#577
Open
stian-sandvold wants to merge 1 commit into
Open
Conversation
…21757] The bespoke GET /api/dataEntry/metadata endpoint walks the whole metadata entity graph via lazy Hibernate associations, causing an N+1 query explosion (10,202 SQL statements / 245s / HTTP 500 on the Uganda instance). Its cost scales with the size of the user's writable metadata. Rebuild the same metadata client-side from flat, bulk, per-type requests to the standard metadata endpoints instead. useMetadata()'s return shape is unchanged (id-keyed dicts via hashArraysInObject), so every selector and consumer is untouched. Verified byte-equivalent against the real endpoint on the Sierra Leone demo (757 entities across 7 types match exactly), and ~6-8x fewer SQL statements (~230-300 vs ~1,880), well-batched per type. Also marks the query meta.persist so the preloaded metadata survives reloads and is available offline (the endpoint's original purpose). Co-Authored-By: Claude Opus 4.8 <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.



The bespoke GET /api/dataEntry/metadata endpoint walks the whole metadata entity graph via lazy Hibernate associations, causing an N+1 query explosion (10,202 SQL statements / 245s / HTTP 500 on the Uganda instance). Its cost scales with the size of the user's writable metadata.
Rebuild the same metadata client-side from flat, bulk, per-type requests to the standard metadata endpoints instead. useMetadata()'s return shape is unchanged (id-keyed dicts via hashArraysInObject), so every selector and consumer is untouched. Verified byte-equivalent against the real endpoint on the Sierra Leone demo (757 entities across 7 types match exactly), and ~6-8x fewer SQL statements (~230-300 vs ~1,880), well-batched per type.
Also marks the query meta.persist so the preloaded metadata survives reloads and is available offline (the endpoint's original purpose).