optimize: avoid redundant DB call when account matches calling account#11403
optimize: avoid redundant DB call when account matches calling account#11403shwstppr wants to merge 2 commits into
Conversation
Use Account object from call context when possible Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11403 +/- ##
============================================
- Coverage 17.35% 17.35% -0.01%
+ Complexity 15231 15229 -2
============================================
Files 5885 5885
Lines 525611 525630 +19
Branches 64160 64164 +4
============================================
- Hits 91224 91217 -7
- Misses 424090 424115 +25
- Partials 10297 10298 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
|
@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 14579 |
|
@blueorangutan test |
|
@shwstppr a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-14047)
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes event publishing by avoiding redundant database calls to fetch account objects when the account ID matches the calling account ID from CallContext. This improves performance by reusing the already-loaded account object from the call context instead of making an unnecessary database query.
Changes:
- Added conditional logic to retrieve account from CallContext when accountId matches the calling account
- Updated test setup to register CallContext once in setup/teardown instead of per-test
- Removed unnecessary mock for accountDao.findById in tests since the optimization bypasses this call
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/src/main/java/com/cloud/event/ActionEventUtils.java | Added optimization to use CallContext.current().getCallingAccount() when accountId matches calling account ID |
| engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java | Added same optimization for usage event publishing |
| server/src/test/java/com/cloud/event/ActionEventUtilsTest.java | Moved CallContext registration to setup/teardown and removed accountDao mock |
| server/src/test/java/com/cloud/event/ActionEventInterceptorTest.java | Removed accountDao mock but introduced duplicate CallContext registration bug |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -175,8 +175,6 @@ public EventVO answer(InvocationOnMock invocation) throws Throwable { | |||
| user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", | |||
| UUID.randomUUID().toString(), User.Source.UNKNOWN); | |||
| CallContext.register(user, account); | |||
There was a problem hiding this comment.
CallContext is being registered twice - once here in setupCommonMocks() and once in the setup() method at line 143. Since setup() calls setupCommonMocks(), this results in duplicate registration. Remove this line and keep only the registration in the setup() method to maintain consistency with the ActionEventUtilsTest pattern.
| CallContext.register(user, account); |
Description
Use Account object from call context when possible
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?