Skip to content

[BI-1294] Implement Caching Layer for Experiments#264

Merged
dmeidlin merged 16 commits intodevelopfrom
feature/BI-1294
Jul 17, 2023
Merged

[BI-1294] Implement Caching Layer for Experiments#264
dmeidlin merged 16 commits intodevelopfrom
feature/BI-1294

Conversation

@dmeidlin
Copy link
Contributor

@dmeidlin dmeidlin commented Jun 13, 2023

Description

Story: BI-1294

An instance of ProgramCache was added as a field in BrAPITrialDAO for caching experiments on the redis server. Methods in the DAO were updated to create,update, and read experiemnts from the cache. The program key was stripped from the trial name before storing in the cache.

Dependencies

none

Testing

Verify that experiment importing, exporting, and displaying of experiments in both group table and individual table still works as expected with lower latency.

Checklist:

  • I have performed a self-review of my own code
  • I have tested my code and ensured it meets the acceptance criteria of the story
  • I have tested that my code works with both the brapi-java-server and BreedBase
  • I have create/modified unit tests to cover this change
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to documentation
  • I have run TAF: <please include a link to TAF run>

@dmeidlin dmeidlin requested review from a team, mlm483 and nickpalladino and removed request for a team June 13, 2023 18:35
Copy link
Contributor

@mlm483 mlm483 left a comment

Choose a reason for hiding this comment

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

Looks really good. I learned more about our caching layer.

Please consider my suggestions, but I don't consider them critical, this looks OK to merge.

}
}

private Map<String, BrAPITrial> fetchProgramExperiment(UUID programId) throws ApiException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would fetchProgramExperiments be more accurate, as one Program can have many Experiments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good catch! updated.

return experimentById(processExperimentsForDisplay(programExperiments, program.getKey()));
}

private Map<String, BrAPITrial> experimentById(List<BrAPITrial> trials) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would experimentsById be a more accurate method name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaving the name as is because it's describing the hashmap returned that stores a single experiment for a given id.

Comment on lines +123 to +125
public List<BrAPITrial> getTrialsByName(List<String> trialNames, Program program) throws ApiException {
Map<String, BrAPITrial> cache = programExperimentCache.get(program.getId());
List<BrAPITrial> trials = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Tim mentioned that we may eventually use something like RediSearch to optimize these methods, might be worth putting a TODO comment anywhere that will need to be updated. Unless you think it will be obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I added a comment.

Comment on lines 226 to 231
public Optional<BrAPITrial> getTrialByDbId(String trialDbId, Program program) throws ApiException {
List<BrAPITrial> trials = getTrialsByDbIds(List.of(trialDbId), program);
return Utilities.getSingleOptional(trials);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to either

  1. remove this unused method, or
  2. update it to utilize the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It already uses the cache viagetTrialsByDbIds. As for the unused methods, it was decided in discussions with Tim to leave these in place for now.

@dmeidlin dmeidlin force-pushed the feature/BI-1294 branch 2 times, most recently from 73a732b to b5c2e5d Compare June 30, 2023 15:44
@dmeidlin dmeidlin merged commit 66db2b2 into develop Jul 17, 2023
@dmeidlin dmeidlin deleted the feature/BI-1294 branch July 17, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants