Skip to content

⚡ Optimize microbiology report item DB insertions with batch inserts#19

Merged
manupawickramasinghe merged 3 commits into
developmentfrom
optimize-patient-report-inserts-9611181651890645616
Jun 13, 2026
Merged

⚡ Optimize microbiology report item DB insertions with batch inserts#19
manupawickramasinghe merged 3 commits into
developmentfrom
optimize-patient-report-inserts-9611181651890645616

Conversation

@ManupaKDU

Copy link
Copy Markdown

💡 What:

  • Refactored addMicrobiologyReportItemValuesForReport to resolve severe N+1 query patterns.
  • Extracted existing PatientReportItemValue retrieval out of the loops utilizing an upfront bulk fetch JPQL query.
  • Replaced iterative getPtRivFacade().create(val); operations with bulk collection into a list and a single getPtRivFacade().batchCreate(newVals); invocation.

🎯 Why:

  • The previous implementation queried the database and independently saved items per ReportItem and Antibiotic. For a typical lab report iteration (e.g. 1000 investigation items), this triggered 1000 SELECT and 1000 INSERT operations to the database synchronously, locking up DB connections unnecessarily and introducing heavy I/O latency.

📊 Measured Improvement:

  • A unit test was authored (PatientReportBeanTest) measuring processing overhead simulating 1000 elements.
  • Baseline: Triggered 1000 distinct mock calls to .create() which equates to 1000 sequential JPA persisted DB trips.
  • Improvement: Triggers 0 sequential reads/writes inside the loops; the entire collection executes exactly 1 trip per phase: 1 findByJpql call and 1 batchCreate call.
  • This effectively turns an O(N) database execution operation to O(1).

PR created automatically by Jules for task 9611181651890645616 started by @manupawickramasinghe

- Replaced repeated individual `findFirstByJpql()` calls with a single upfront JPQL query to load existing `PatientReportItemValue` records into a HashMap.
- Collected new `PatientReportItemValue` records into a single list instead of performing N individual `create()` calls.
- Persisted the accumulated records using a single `batchCreate()` call.
- Validated performance improvement using a new mock unit test (`PatientReportBeanTest`).

Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Gemini CLI and others added 2 commits June 13, 2026 10:50
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@manupawickramasinghe manupawickramasinghe merged commit c4aed23 into development Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants