fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16138] #15639
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
During a
DataValueSet
import, calls are made to the DB to getOrganisationUnit
s. When there are large amounts ofOrganisationUnit
s this can lead to the import taking a long time.v38
did not experience these issues.Cause
During a large refactor PR the implementation that was working well was changed.
v38
code we checkOrganisationUnit
s that are already in-memory (ImportContext
).v38
we checkOrganisationUnit
s using a service call which in turn calls the DB.Fix
Revert back to original implementation, checking the
OrganisationUnit
s in memory.Needs backporting to:
Testing
The data below is based on following the steps provided in the Jira issue.
Running locally on a Mac.
Also confirmed in the DB logs that the DB query which was being called for
OrganisationUnit
was not called anymore during the import, after the fix.The test setup in
DataValueSetImportValidatorTest
had to be updated to reflect the change. Instead of using a mock response to always return true no matter what, the test now checks the actualOrganisationUnit
path, mirroring actual behaviour in the code.Notes
During the large refactor PR there was a similar change made to this method:
As the reported issue seems to have been resolved we won't include any changes in this method. We will look into this however to prove if similar changes are required or not (even though it seems like an obvious change).
I did test changing it to use the in-memory & it had no difference with the execution time but that may be due to the data being used.