FINERACT-2579: Batch entity lookups in generateLoanProvisioningEntry to eliminate per-row DB calls#5739
Open
AshharAhmadKhan wants to merge 1 commit intoapache:developfrom
Conversation
…to eliminate per-row DB calls
Contributor
Author
|
hey @adamsaghy All the failing checks look like infra issues (eclipse cdn 502s and docker startup timeouts), nothing related to my changes. can you rerun them when you get a chance please? |
Contributor
Author
|
still eclipse cdn 502s, nothing to do with my changes. would appreciate a code review when you get a chance! |
Contributor
Author
|
failing test is unrelated to PR. PR is ready for review. |
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.
Description
JIRA: https://issues.apache.org/jira/browse/FINERACT-2579
The
generateLoanProvisioningEntry()method inProvisioningEntriesWritePlatformServiceJpaRepositoryImplwas firing five individual repository queries per loop iteration —LoanProduct,Office,ProvisioningCategory, and bothGLAccountentries — for every row returned byretrieveLoanProductsProvisioningData(), causing N×5 redundant DB round-trips on every provisioning entry creation or recreation request.Since all referenced IDs are known before the loop begins, this fix collects them upfront and replaces the individual lookups with four bulk
findAllById()calls, reducing the total round-trips from N×5 to 4 regardless of entry count. In-memory map lookups replace the per-row DB calls inside the loop.This is the same class of redundancy fixed in FINERACT-2561 for
saveAllDebitOrCreditEntries(), but more severe — five queries per iteration instead of one, on a batch job path that processes every active loan product across all offices.No logic change — all entity resolution still happens, and proper Fineract exceptions (
LoanProductNotFoundException,OfficeNotFoundException,GLAccountNotFoundException) are thrown if any entity is missing.OfficeRepositoryWrapperis replaced withOfficeRepositorydirectly to enable bulk fetching.