Skip to content

SWATCH-4281: Reduce eager loading for unneeded collection#5699

Open
wottop wants to merge 1 commit intomainfrom
wottop/SWATCH-4281
Open

SWATCH-4281: Reduce eager loading for unneeded collection#5699
wottop wants to merge 1 commit intomainfrom
wottop/SWATCH-4281

Conversation

@wottop
Copy link
Contributor

@wottop wottop commented Feb 19, 2026

  • Targets a specific scenario where monthly totals are not used

Jira issue: SWATCH-4281

Description

In an effort to reduce the data loaded during a nightly tally, we can stop loading instance_montly_totals when loading the hosts. This will save time and memory during this run.

Testing

Setup

  1. make clean install
  2. podman compose up -d
  3. Import data from production
    ./import_hbi_hosts_by_org.sh --org-id=4592029 --batch-mode
    python import-from-gabi.py --org-id=4592029 --systems
  4. Start swatch-tally with SQL debug logging and logging to a file
    SERVER_PORT=8010 ./mvnw -pl swatch-tally spring-boot:run -DskipTests -Dspring-boot.run.arguments="--logging.level.org.hibernate.SQL=DEBUG" > test.log

Steps

  1. Run the nightly tally
    http PUT ":8010/api/rhsm-subscriptions/v1/internal/rpc/tally/snapshots/4592029" x-rh-swatch-psk:placeholder

Verification

  1. Look through the log. You will see this query that does not include a join to instance_montly_totals
    [DEBUG] [org.hibernate.SQL] - select h1_0.id,h1_0.billing_account_id,h1_0.billing_provider,b1_0.host_id,b1_0.as_hypervisor,b1_0.billing_account_id,b1_0.billing_provider,b1_0.product_id,b1_0.sla,b1_0.usage,b1_0.cores,b1_0.measurement_type,b1_0.sockets,b1_0.version,h1_0.cloud_provider,h1_0.display_name,h1_0.is_guest,h1_0.hardware_type,h1_0.hypervisor_uuid,h1_0.insights_id,h1_0.instance_id,h1_0.instance_type,h1_0.inventory_id,h1_0.is_hypervisor,h1_0.is_unmapped_guest,laerdbst1_0.host_id,laerdbst1_0.service_type,laerdbst1_0.last_applied_event_record_date,h1_0.last_seen,m1_0.host_id,m1_0.metric_id,m1_0.value,h1_0.num_of_guests,h1_0.org_id,h1_0.subscription_manager_id from hosts h1_0 left join instance_measurements m1_0 on h1_0.id=m1_0.host_id left join host_tally_buckets b1_0 on h1_0.id=b1_0.host_id left join host_tally_service_type laerdbst1_0 on h1_0.id=laerdbst1_0.host_id where h1_0.org_id=? and h1_0.instance_type='HBI_HOST' order by coalesce(h1_0.hypervisor_uuid,h1_0.subscription_manager_id),h1_0.hypervisor_uuid,h1_0.inventory_id,h1_0.id
  2. There will not be any calls to individually load data from instance_montly_totals

@wottop wottop marked this pull request as draft February 19, 2026 16:48
@wottop wottop force-pushed the wottop/SWATCH-4281 branch from 83b0850 to e9b1710 Compare February 19, 2026 16:48
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

⛏️ Workflow Run

🧹 Checkstyle

🧪 JUnit

TestsPassed ✅Skipped ⚠️Failed
JUnit Test Report1915 ran1910 passed5 skipped0 failed
Details
TestResult
No test annotations available

@wottop wottop force-pushed the wottop/SWATCH-4281 branch 3 times, most recently from 047c3fb to 15a07d6 Compare February 23, 2026 13:37
@wottop wottop force-pushed the wottop/SWATCH-4281 branch 2 times, most recently from c944cb3 to 87d2b63 Compare March 2, 2026 19:26
@wottop wottop marked this pull request as ready for review March 2, 2026 19:26
@wottop wottop force-pushed the wottop/SWATCH-4281 branch 2 times, most recently from 96c7240 to 69eb18d Compare March 3, 2026 13:49
@wottop wottop added QE Unneeded Pull request does not need QE approval Dev Pull requests that need developer review labels Mar 3, 2026
awood
awood previously approved these changes Mar 5, 2026
SELECT h FROM Host h
LEFT JOIN FETCH h.monthlyTotals
""")
List<Host> findAllEagerly();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
List<Host> findAllEagerly();
/* Used in testing since we don't have a session that can resolve the proxy objects associated with a
* lazy fetch */
List<Host> findAllEagerly();

- Targets a specific scenario where monthly totals are not used
@wottop wottop force-pushed the wottop/SWATCH-4281 branch from ae26828 to 8284988 Compare March 6, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev Pull requests that need developer review QE Unneeded Pull request does not need QE approval swatch-system-conduit swatch-tally team-thunder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants