fix: skip enrollment-notes preheat query for WITHOUT_REGISTRATION synthetic enrollments - #25006
Draft
jason-p-pickering wants to merge 3 commits into
Draft
fix: skip enrollment-notes preheat query for WITHOUT_REGISTRATION synthetic enrollments#25006jason-p-pickering wants to merge 3 commits into
jason-p-pickering wants to merge 3 commits into
Conversation
…thetic enrollments EnrollmentSupplier preheats a synthetic Enrollment for every WITHOUT_REGISTRATION program an import touches, using the shared preheat EnrollmentMapper which mapped `notes`. That mapping forces Hibernate to lazy-load enrollment_notes/note for every such enrollment, even though this synthetic entity is only ever used as an FK reference for events and is never converted or persisted, so its notes are never read. Give it a notes-free mapping variant instead. EnrollmentStrategy (which preheats real enrollments referenced by UID) keeps using the notes-inclusive mapping, since merge() there relies on it to avoid orphan-deleting existing notes.
jason-p-pickering
marked this pull request as draft
September 1, 2026 06:26
|
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
EnrollmentSupplierpreheats a syntheticEnrollmentfor everyWITHOUT_REGISTRATIONprogram an import touches. It used the shared preheatEnrollmentMapper, whose@Mapping(target = "notes")forces Hibernate to lazy-loadenrollment_notes/notefor every such enrollment — even though this synthetic entity is only ever used as an FK reference for events (event.setEnrollment(...)) and is never converted or persisted, so its notes are never read. On a single-event import this fires one dead query perWITHOUT_REGISTRATIONprogram, every time.EnrollmentMapper.mapWithoutNotes(Enrollment)— same mapping asmap()minusnotes— and switchedEnrollmentSupplierto use it.EnrollmentStrategy(which preheats real enrollments referenced by UID in a tracker payload) keeps using the notes-inclusivemap():AbstractTrackerPersistercallsentityManager.merge(...)on update, andEnrollment.notesiscascade="all-delete-orphan", so skipping the eager load there would silently delete every existing note on every enrollment update. The fix is scoped toEnrollmentSupplieronly.@Mapping(target = "notes")exists on master too, so this is not a 2.41-only regression, just a 2.41-only fix for now (consistent with prior single-event preheat fixes on this branch).Found via a Glowroot trace on a production single-event import, live-validated: smoke-tested a built
dhis.waragainst the target instance and confirmed the query disappears from the trace.Test plan
EnrollmentSupplierTest.verifySupplierDoesNotAccessNotesOfEnrollmentWithoutRegistrationspies on a realEnrollmentand assertsgetNotes()is never called during preheat; confirmed it fails against pre-fix code (Mockito pointed atEnrollmentMapperImpl.map()), passes post-fix.preheat/converter/bundlepackage regression sweep indhis-service-tracker: 129 tests, 0 failures.dhis.warfrom this branch merged into a downstream integration branch and smoke-tested against a production-like single-event import; confirmed theenrollment_notes JOIN notequery no longer appears in the trace.