perf: pre-filter geoFeatures org units by geometry (#24279) [2.42]#24492
Merged
Conversation
* perf: pre-filter geoFeatures org units by geometry geoFeatures resolves the `ou` dimension into full OrganisationUnit entities, then discards every unit without geometry in-memory. On a large hierarchy (Nigeria prod: ~255k level-5 units, all null-geometry) this hydrates a quarter-million entities — ~7.6s CPU and ~4.7 GB allocated — only to return []. Thread an optional `geometryOnly` flag from DataQueryRequest through DimensionalObjectProvider and OrganisationUnitService down to HibernateOrganisationUnitStore, which appends `and o.geometry is not null`. Default off, so all other callers dispatch the original 2-arg methods unchanged. Skipped in geoJsonAttribute (coordinateField) mode, where coordinates come from an attribute and the geometry column may be null. The in-memory filter remains the precise final gate. When the geometry-filtered resolution is empty, the E7143 empty-dimension guard is suppressed so geoFeatures still returns 200 [] rather than an error. Validated on production (Nigeria, deployed on 2.40): a comparable high-level layer dropped from ~8.6s/4.7GB to 14ms/747KB. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor: bundle getDimension args into DimensionResolveOptions The private getDimension dispatcher grew to 8 parameters when geometryOnly was threaded through, tripping SonarQube java:S107 (>7 parameters). Bundle the five resolution options (relativePeriodDate, displayProperty, allowNull, inputIdScheme, geometryOnly) into a private DimensionResolveOptions record, bringing the method to 4 parameters. Behaviour is unchanged; contained entirely within DefaultDataQueryService. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
netroms
approved these changes
Jul 23, 2026
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
Backport of #24279 to 2.42.
geoFeatures resolves the
oudimension into full OrganisationUnit entities, then discards every unit without geometry in-memory. On a large hierarchy (Nigeria prod: ~255k level-5 units, all null-geometry) this hydrates a quarter-million entities — ~7.6s CPU and ~4.7 GB allocated — only to return[].This threads an optional
geometryOnlyflag fromDataQueryRequestthroughDimensionalObjectProviderandOrganisationUnitServicedown toHibernateOrganisationUnitStore, which appendsand o.geometry is not null. Default off, so all other callers dispatch the original methods unchanged. Skipped in geoJsonAttribute (coordinateField) mode, where coordinates come from an attribute and the geometry column may be null. The in-memory filter remains the precise final gate.When the geometry-filtered resolution is empty, the E7143 empty-dimension guard is suppressed so geoFeatures still returns 200
[]rather than an error.Validated on production (Nigeria, deployed on 2.40): a comparable high-level layer dropped from ~8.6s/4.7GB to 14ms/747KB.
Backport notes
Cherry-pick of 2c7ee45 onto 2.42 hit conflicts because 2.42 lacks a master-only feature (stage-specific category/COGS dimension resolution in
DefaultDataQueryService) — resolved by keeping 2.42's existing dispatch path and applying only the geometry-only wiring. A related type mismatch inDimensionalObjectProvider.getOrgUnitDimension(auto-merged without conflict markers but broke compilation) was fixed by aligning the new overload's return type with 2.42's existingBaseDimensionalObjectsignature.Test plan
dhis-service-analyticsanddhis-web-api(main + test sources) compile cleanlyspotless:checkpassesCo-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com