Skip to content

Commit

Permalink
Enable multi-study study-view cache (#10764)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalletlak committed Apr 29, 2024
1 parent e9e6a45 commit f38bc51
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 62 deletions.
108 changes: 56 additions & 52 deletions src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ public ResponseEntity<List<ClinicalDataCountItem>> fetchClinicalDataCounts(
if (attributes.size() == 1) {
studyViewFilterUtil.removeSelfFromFilter(attributes.get(0).getAttributeId(), studyViewFilter);
}
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(studyViewFilter);
List<ClinicalDataCountItem> result =
this.getInstance().cachedClinicalDataCounts(interceptedClinicalDataCountFilter,singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(studyViewFilter);
List<ClinicalDataCountItem> result =
this.getInstance().cachedClinicalDataCounts(interceptedClinicalDataCountFilter,
unfilteredQuery);
return new ResponseEntity<>(result, HttpStatus.OK);

}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<ClinicalDataCountItem> cachedClinicalDataCounts(
ClinicalDataCountFilter interceptedClinicalDataCountFilter, boolean singleStudyUnfiltered
) {
public List<ClinicalDataCountItem> cachedClinicalDataCounts(ClinicalDataCountFilter interceptedClinicalDataCountFilter,
boolean unfilteredQuery) {
List<ClinicalDataFilter> attributes = interceptedClinicalDataCountFilter.getAttributes();
StudyViewFilter studyViewFilter = interceptedClinicalDataCountFilter.getStudyViewFilter();
if (attributes.size() == 1) {
Expand Down Expand Up @@ -216,21 +216,22 @@ public ResponseEntity<List<ClinicalDataBin>> fetchClinicalDataBinCounts(
@Valid @RequestAttribute(required = false, value = "interceptedClinicalDataBinCountFilter") ClinicalDataBinCountFilter interceptedClinicalDataBinCountFilter
) {
StudyViewFilter studyViewFilter = clinicalDataBinUtil.removeSelfFromFilter(interceptedClinicalDataBinCountFilter);
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(studyViewFilter);
List<ClinicalDataBin> clinicalDataBins =
this.getInstance().cachableFetchClinicalDataBinCounts(dataBinMethod, interceptedClinicalDataBinCountFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(studyViewFilter);
List<ClinicalDataBin> clinicalDataBins =
this.getInstance().cachableFetchClinicalDataBinCounts(dataBinMethod,
interceptedClinicalDataBinCountFilter,
unfilteredQuery);

return new ResponseEntity<>(clinicalDataBins, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<ClinicalDataBin> cachableFetchClinicalDataBinCounts(
DataBinMethod dataBinMethod,
ClinicalDataBinCountFilter interceptedClinicalDataBinCountFilter,
boolean singleStudyUnfiltered
public List<ClinicalDataBin> cachableFetchClinicalDataBinCounts(DataBinMethod dataBinMethod,
ClinicalDataBinCountFilter interceptedClinicalDataBinCountFilter,
boolean unfilteredQuery
) {
return clinicalDataBinUtil.fetchClinicalDataBinCounts(
dataBinMethod,
Expand Down Expand Up @@ -287,18 +288,18 @@ public ResponseEntity<List<AlterationCountByGene>> fetchMutatedGenes(
@Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above.
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) throws StudyNotFoundException {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<AlterationCountByGene> alterationCountByGenes = this.getInstance().cachedFetchMutatedGenes(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<AlterationCountByGene> alterationCountByGenes = this.getInstance().cachedFetchMutatedGenes(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(alterationCountByGenes, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<AlterationCountByGene> cachedFetchMutatedGenes(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) throws StudyNotFoundException {
public List<AlterationCountByGene> cachedFetchMutatedGenes(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery) throws StudyNotFoundException {
AlterationFilter annotationFilters = interceptedStudyViewFilter.getAlterationFilter();

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
Expand Down Expand Up @@ -327,19 +328,19 @@ public ResponseEntity<List<AlterationCountByGene>> fetchStructuralVariantGenes(
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) throws StudyNotFoundException {

boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<AlterationCountByGene> alterationCountByGenes =
this.getInstance().cacheableFetchStructuralVariantGenes(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<AlterationCountByGene> alterationCountByGenes =
this.getInstance().cacheableFetchStructuralVariantGenes(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(alterationCountByGenes, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<AlterationCountByGene> cacheableFetchStructuralVariantGenes(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) throws StudyNotFoundException {
public List<AlterationCountByGene> cacheableFetchStructuralVariantGenes(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery) throws StudyNotFoundException {
AlterationFilter annotationFilters = interceptedStudyViewFilter.getAlterationFilter();

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
Expand Down Expand Up @@ -368,19 +369,19 @@ public ResponseEntity<List<AlterationCountByStructuralVariant>> fetchStructuralV
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) throws StudyNotFoundException {

boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<AlterationCountByStructuralVariant> alterationCountByStructuralVariants =
this.getInstance().cacheableFetchStructuralVariantCounts(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<AlterationCountByStructuralVariant> alterationCountByStructuralVariants =
this.getInstance().cacheableFetchStructuralVariantCounts(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(alterationCountByStructuralVariants, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<AlterationCountByStructuralVariant> cacheableFetchStructuralVariantCounts(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) throws StudyNotFoundException {
public List<AlterationCountByStructuralVariant> cacheableFetchStructuralVariantCounts(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery) {

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
if(CollectionUtils.isNotEmpty(sampleIdentifiers)) {
Expand All @@ -406,16 +407,18 @@ public ResponseEntity<List<CopyNumberCountByGene>> fetchCNAGenes(
@Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above.
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) throws StudyNotFoundException {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<CopyNumberCountByGene> copyNumberCountByGenes = this.getInstance().cacheableFetchCNAGenes(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<CopyNumberCountByGene> copyNumberCountByGenes = this.getInstance().cacheableFetchCNAGenes(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(copyNumberCountByGenes, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<CopyNumberCountByGene> cacheableFetchCNAGenes(StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered) throws StudyNotFoundException {
public List<CopyNumberCountByGene> cacheableFetchCNAGenes(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery) throws StudyNotFoundException {
AlterationFilter alterationFilter = interceptedStudyViewFilter.getAlterationFilter();

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
Expand Down Expand Up @@ -473,18 +476,18 @@ public ResponseEntity<List<GenomicDataCount>> fetchMolecularProfileSampleCounts(
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
)
{
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<GenomicDataCount> sampleCounts = this.getInstance().cacheableFetchMolecularProfileSampleCounts(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<GenomicDataCount> sampleCounts = this.getInstance().cacheableFetchMolecularProfileSampleCounts(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(sampleCounts, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<GenomicDataCount> cacheableFetchMolecularProfileSampleCounts(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) {
public List<GenomicDataCount> cacheableFetchMolecularProfileSampleCounts(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<GenomicDataCount> genomicDataCounts = new ArrayList<>();
if(CollectionUtils.isNotEmpty(sampleIdentifiers)) {
Expand Down Expand Up @@ -1149,18 +1152,19 @@ public ResponseEntity<List<ClinicalEventTypeCount>> getClinicalEventTypeCounts(
@RequestAttribute(required = false, value = "interceptedStudyViewFilter")
StudyViewFilter interceptedStudyViewFilter
) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<ClinicalEventTypeCount> eventTypeCounts = this.getInstance().cachedClinicalEventTypeCounts(interceptedStudyViewFilter, singleStudyUnfiltered);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<ClinicalEventTypeCount> eventTypeCounts = this.getInstance().cachedClinicalEventTypeCounts(interceptedStudyViewFilter,
unfilteredQuery);
return new ResponseEntity<>(eventTypeCounts, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<ClinicalEventTypeCount> cachedClinicalEventTypeCounts(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
){
public List<ClinicalEventTypeCount> cachedClinicalEventTypeCounts(StudyViewFilter interceptedStudyViewFilter,
boolean unfilteredQuery
) {
List<SampleIdentifier> filteredSampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<String> sampleIds = new ArrayList<>();
List<String> studyIds = new ArrayList<>();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/cbioportal/web/TreatmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ public ResponseEntity<List<PatientTreatmentRow>> getAllPatientTreatments(
@RequestAttribute(required = false, value = "interceptedStudyViewFilter")
StudyViewFilter interceptedStudyViewFilter
) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<PatientTreatmentRow> treatments =
this.getInstance().cachableGetAllPatientTreatments(tier, interceptedStudyViewFilter, singleStudyUnfiltered);
this.getInstance().cachableGetAllPatientTreatments(tier, interceptedStudyViewFilter, unfilteredQuery);
return new ResponseEntity<>(treatments, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<PatientTreatmentRow> cachableGetAllPatientTreatments(
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean unfilteredQuery
) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<String> sampleIds = new ArrayList<>();
Expand Down Expand Up @@ -139,18 +139,18 @@ public ResponseEntity<List<SampleTreatmentRow>> getAllSampleTreatments(
@RequestAttribute(required = false, value = "interceptedStudyViewFilter")
StudyViewFilter interceptedStudyViewFilter
) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
boolean unfilteredQuery = studyViewFilterUtil.isUnfilteredQuery(interceptedStudyViewFilter);
List<SampleTreatmentRow> treatments =
this.getInstance().cacheableGetAllSampleTreatments(tier, interceptedStudyViewFilter, singleStudyUnfiltered);
this.getInstance().cacheableGetAllSampleTreatments(tier, interceptedStudyViewFilter, unfilteredQuery);
return new ResponseEntity<>(treatments, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery"
)
public List<SampleTreatmentRow> cacheableGetAllSampleTreatments(
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean unfilteredQuery
) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<String> sampleIds = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ public List<ClinicalDataCountItem> getClinicalDataCountsFromCustomData(Collectio
}).collect(Collectors.toList());
}

public boolean isSingleStudyUnfiltered(StudyViewFilter filter) {
public boolean isUnfilteredQuery(StudyViewFilter filter) {
return filter.getStudyIds() != null &&
filter.getStudyIds().size() == 1 &&
(filter.getClinicalDataFilters() == null || filter.getClinicalDataFilters().isEmpty()) &&
(filter.getGeneFilters() == null || filter.getGeneFilters().isEmpty()) &&
(filter.getSampleTreatmentFilters() == null || filter.getSampleTreatmentFilters().getFilters().isEmpty()) &&
Expand Down

0 comments on commit f38bc51

Please sign in to comment.