[BI-1647] View Experiments: Observation Dataset Table#280
Merged
Conversation
mlm483
requested changes
Aug 7, 2023
Contributor
mlm483
left a comment
There was a problem hiding this comment.
- One change requested for performance, I tested my suggested code change it was an order of magnitude faster locally for a large experiment (16731 Observations).
- Probably out of scope for this story, but if you see an easy way to tackle this performance story I just created, please do!
src/main/java/org/breedinginsight/brapps/importer/daos/BrAPIObservationUnitDAO.java
Show resolved
Hide resolved
Comment on lines
+130
to
+134
| for (BrAPIObservationUnit observationUnit: observationUnits) { | ||
| String germplasmDbId = observationUnit.getGermplasmDbId(); | ||
| BrAPIGermplasm germplasm = this.germplasmService.getGermplasmByDBID(program.getId(), germplasmDbId).get() ; | ||
| observationUnit.putAdditionalInfoItem("gid", germplasm.getAccessionNumber()); | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| for (BrAPIObservationUnit observationUnit: observationUnits) { | |
| String germplasmDbId = observationUnit.getGermplasmDbId(); | |
| BrAPIGermplasm germplasm = this.germplasmService.getGermplasmByDBID(program.getId(), germplasmDbId).get() ; | |
| observationUnit.putAdditionalInfoItem("gid", germplasm.getAccessionNumber()); | |
| } | |
| // Load germplasm for program into map. | |
| // TODO: if we use redis search, that may be more efficient than loading all germplasm for the program. | |
| HashMap<String, BrAPIGermplasm> germplasmByDbId = new HashMap<>(); | |
| this.germplasmService.getGermplasm(programId).forEach((germplasm -> germplasmByDbId.put(germplasm.getGermplasmDbId(), germplasm))); | |
| for (BrAPIObservationUnit observationUnit: observationUnits) { | |
| BrAPIGermplasm germplasm = germplasmByDbId.get(observationUnit.getGermplasmDbId()); | |
| observationUnit.putAdditionalInfoItem("gid", germplasm.getAccessionNumber()); | |
| } |
This is loading all Germplasm in the program from the cache for each observationUnit, which really hurts performance for large datasets. I would load all germplasm for the program into a HashMap (key: germplasmDbId => value: Germplasm object) outside of the for loop and then access by key inside the loop.
I think there's an eventual desire to use something like https://redis.io/docs/interact/search-and-query/ to make more fine-grained cache retrievals, but for now, just use a HashMap.
Contributor
Author
There was a problem hiding this comment.
Excellent! Thank you.
Done.
nickpalladino
requested changes
Aug 14, 2023
Comment on lines
+130
to
+134
| for (BrAPIObservationUnit observationUnit: observationUnits) { | ||
| String germplasmDbId = observationUnit.getGermplasmDbId(); | ||
| BrAPIGermplasm germplasm = this.germplasmService.getGermplasmByDBID(program.getId(), germplasmDbId).get() ; | ||
| observationUnit.putAdditionalInfoItem("gid", germplasm.getAccessionNumber()); | ||
| } |
| for (BrAPIObservationUnit observationUnit: observationUnits) { | ||
| String germplasmDbId = observationUnit.getGermplasmDbId(); | ||
| BrAPIGermplasm germplasm = this.germplasmService.getGermplasmByDBID(program.getId(), germplasmDbId).get() ; | ||
| observationUnit.putAdditionalInfoItem("gid", germplasm.getAccessionNumber()); |
Member
There was a problem hiding this comment.
Can we add gid to BrAPIAdditionalInfoFields constants and use that here?
nickpalladino
approved these changes
Aug 22, 2023
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
BI-1647 (View Experiments: Observation Dataset Table)
Added the ability to retrieve the GID in the additional information element of the Observation Unit.
Dependencies
bi-web: branch feature/BI-1647
Testing
see bi-web PR.
Checklist: