Skip to content

[BI-2806] Remove trials cache#516

Open
jloux-brapi wants to merge 13 commits into
epic/BI-2862from
feature/BI-2806
Open

[BI-2806] Remove trials cache#516
jloux-brapi wants to merge 13 commits into
epic/BI-2862from
feature/BI-2806

Conversation

@jloux-brapi

@jloux-brapi jloux-brapi commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Story: BI-2806

The body of changes in this MR effectively removes the cache implementation for BrAPITrials in bi-api.

There's quite a lot in here, so I'll try to sum up the important areas:

BrAPITrialDAOImpl was edited to

  • Retrieve trials by ID via brapi trialDbId
  • getTrialMethods updated utilize above method
  • createTrials uses brapi post with no update to the cache
  • updateTrial uses brapi put with no update to the cache
  • deleteTrial uses brapi delete with no update to the cache
  • repopulateCache method and usages deleted
  • fetch method deleted which grabbed all trials for a program from brapi whenever post, put, delete was made
  • Trial cache removed.

Various entities in need of relation to a trial were updated to use the bi-api generated trial ex ref id from the trial itself like Study, List. These can be changed after the cache is removed

Fixed some instances where certain controllers automatically updated the BrAPITrialDbId in the entity to the bi generated id, which was breaking compatability.

Unit tests were updated to support the changes. Many of these unit tests depended on the bi-api generated uuid from the workflow response to pass through to methods which validated everything. This doesn't really work with the cache gone for trials because now it needs to validate on the trialDbId for the created record. Tests have been updated to grab these IDs from the brapiDb once the workflows complete.

Dependencies

bi-web

Testing

Regression on just about anything Experiment related, including:

  • Experiment creation
  • Experiment deletion
  • Experiment updates
  • Experiment Collaborator checks
  • Experiment viewing
  • Dataset viewing
  • Dataset creation
  • Dataset appending

Verify there are no log messages related to caching trials for a program by looking at logs once above tests have been completed.

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 create/modified unit and/or integration tests to cover this change or tests are not applicable
  • I have commented my code, particularly in hard-to-understand areas
  • I have either updated the source of truth or arranged for update with product owner if needed https://breedinginsight.atlassian.net/wiki/spaces/BI/pages/1559953409/Source+of+Truth

return getTrialsFromBrAPI(program, trialQueryParams);
}

private Map<String, BrAPITrial> fetchProgramExperiments(UUID programId) throws ApiException {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Don't really love the way github is presenting this.

fetchProgramExperiments() is essentially what was called by the trialCache every time it was updated.

This method was removed completely along with the cache.

The "change" to this method is not really a change at all, this is a brand new method specifically for grabbing trials from BrAPI.

return trials;
}

private List<BrAPITrial> getTrialsByExRef(String referenceSource, String referenceId, Program program) throws ApiException {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This method was unused and removed.

}

public List<BrAPITrial> getExperiments(UUID programId) throws ApiException, DoesNotExistException {
// TODO: Edit this to filter/paginate trials

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This will be important for BI-2861

// get requested environments for the experiment
log.debug(logHash + ": fetching environments for export");
List<BrAPIStudy> expStudies = studyDAO.getStudiesByExperimentID(experimentId, program);
List<BrAPIStudy> expStudies = studyDAO.getStudiesByExperimentID(UUID.fromString(expExRefId), program);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Study lookup will still occur on BI generated ID stored in exrefs. We can change this in this epic after we finish removing the cache for other entities. We will run into similar changes updating other entities in the process of removing the cache I'm sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Link to epic just points to this PR

// Make request to delete experiment.
trialDAO.deleteBrAPITrial(program, trial, hard);
// Get all lists for the trial.
// TODO: Get lists by trialDbId if trials get decoupled from datasets.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Lists still require the BI-API generated ID as well.

.orElseThrow(() -> new IllegalStateException("No BI external reference found"))
.getReferenceID());

study.trialDbId(Utilities.getExternalReference(study.getExternalReferences(), Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is kind of a get ahead of the curve change. It might be able to remain as is, but might be tough to find later on when we use trialDbIds directly for studies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ya probably ok for poc but could cause confusing issues mixing deltabreed UUIDs and BrAPI UUIDs.


// TODO: Remove for trialDbId once cache is removed for that entity
private void setDbIds(BrAPITrial trial) {
trial.trialDbId(Utilities.getExternalReference(trial.getExternalReferences(), Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS))

@jloux-brapi jloux-brapi May 6, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was preventing the frontend effectively from being able to use brapiTrialDbIds in the router. Bit of a nasty bugger. Expecting more changes like this in the future for other entities.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another thing I think we'll need to resolve is having inconsistent UUIDs like using the BrAPI trialDbId here but then the DeltaBreed program UUID below.

.getBrAPIObject()
.setTrialDbId(createdTrial.getTrialDbId());
// TODO: May need to set the main ID for pending objects with the BrAPI ID for downstream usage once cache is removed.
trialByNameNoScope.get(createdTrialName)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure we can live without this change. Originally I made this change to see if it would help the unit tests pick up the dbId in the workflow responses but to no avail.

String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName()))
.orElseThrow(() -> new InternalServerException("An Experiment ID was not found in any of the external references"));
UUID experimentId = UUID.fromString(experimentIDRef.getReferenceId());
UUID experimentId = UUID.fromString(existingTrial.getTrialDbId());

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Originating caller of this method is never used. We might want to do away with this whole call stack at this point

@jloux-brapi

Copy link
Copy Markdown
Collaborator Author

I've tagged all developers to review this code since it's essentially the basis of changes that will need to be made throughout 1.5. This will be good for exposure to get familiar with this kind of code as we make changes to it.

@davedrp davedrp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nicely documented. Thanks

@jloux-brapi jloux-brapi added the on hold Do not merge until this label is removed label May 15, 2026
@jloux-brapi

Copy link
Copy Markdown
Collaborator Author

I've added the on hold label to this MR. This should not be merged until this label is removed.

@HMS17 HMS17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good and seconding the nicely commented! Approved contingent on the todos getting cards associated with them before merging.

@humsika humsika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks good to me.

@jloux-brapi

Copy link
Copy Markdown
Collaborator Author

@HMS17 I updated relevant TODO comments in this PR with ticket numbers in the other one which will be merged into this one eventually: #521

@nickpalladino nickpalladino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work, few comments, more thoughts than anything actionable other than possible future work. Do we already have cards to address the bi-api brapi endpoints like /observationunits?trialDbId. Currently that will use the passed in trialDbId for an exref filter in the brapi search but the /trials endpoint will return the trialDbId now instead of the deltabreed UUID so if that is used to retrieve the id the id won't match.


// TODO: Remove for trialDbId once cache is removed for that entity
private void setDbIds(BrAPITrial trial) {
trial.trialDbId(Utilities.getExternalReference(trial.getExternalReferences(), Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another thing I think we'll need to resolve is having inconsistent UUIDs like using the BrAPI trialDbId here but then the DeltaBreed program UUID below.

.orElseThrow(() -> new IllegalStateException("No BI external reference found"))
.getReferenceID());

study.trialDbId(Utilities.getExternalReference(study.getExternalReferences(), Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ya probably ok for poc but could cause confusing issues mixing deltabreed UUIDs and BrAPI UUIDs.

brapiProgramDbId = programDAO.getProgramBrAPI(program).getProgramDbId();
}

// TODO: Configurable max amount of trials per program, or paginate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this is being handled in BI-2932

}

@Override
public List<BrAPITrial> getTrialsByName(List<String> trialNames, Program program) throws ApiException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could probably add a card to update this to use a brapi search instead as a low priority

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was done via BI-2861

@Inject
public BrAPITrialDAOImpl(ProgramCacheProvider programCacheProvider,
ProgramDAO programDAO,
public BrAPITrialDAOImpl(ProgramDAO programDAO,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was kind of thinking we might be able to create a non-cache implementation of the DAO interface but see the interface changed and will have different assumptions about ids so probably not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I didn't feel the need to do that because there didn't seem a need to keep the cache implementation version around

@jloux-brapi

Copy link
Copy Markdown
Collaborator Author

@nickpalladino

Do we already have cards to address the bi-api brapi endpoints like /observationunits?trialDbId.
Regarding this, no, there's no direct card created. We an make one, but I figured it might be covered as part of a spike in the observationunits cache removal.

Because it's related to the trial cache it might make more sense to make a bugfix for it.

@jloux-brapi jloux-brapi removed the on hold Do not merge until this label is removed label Jun 24, 2026
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.

5 participants