From f0cf5dd39c9fde73bbc897af0e552b49ee1d8c99 Mon Sep 17 00:00:00 2001 From: Onur Sumer Date: Thu, 12 Dec 2024 16:22:39 -0500 Subject: [PATCH] make xy plot data cacheable --- .../service/StudyViewColumnarService.java | 2 ++ .../impl/StudyViewColumnarServiceImpl.java | 30 ++++++++++++++++++- .../StudyViewColumnStoreController.java | 8 ++--- .../columnar/util/ClinicalDataXyPlotUtil.java | 14 +++------ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/cbioportal/service/StudyViewColumnarService.java b/src/main/java/org/cbioportal/service/StudyViewColumnarService.java index 4f13dc68f78..67ee1f9efe4 100644 --- a/src/main/java/org/cbioportal/service/StudyViewColumnarService.java +++ b/src/main/java/org/cbioportal/service/StudyViewColumnarService.java @@ -58,4 +58,6 @@ public interface StudyViewColumnarService { List getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List genericAssayDataBinFilters); List getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List genomicDataFilters); + + List fetchClinicalDataForXyPlot(StudyViewFilter studyViewFilter, List attributeIds, boolean shouldFilterNonEmptyClinicalData); } diff --git a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java index d30b77dcc4f..fd8d6051481 100644 --- a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java @@ -28,13 +28,14 @@ import org.cbioportal.web.parameter.GenericAssayDataFilter; import org.cbioportal.web.parameter.GenomicDataBinFilter; import org.cbioportal.web.parameter.GenomicDataFilter; -import org.cbioportal.web.parameter.SampleIdentifier; import org.cbioportal.web.parameter.StudyViewFilter; import org.cbioportal.web.columnar.util.CustomDataFilterUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; +import static org.cbioportal.web.columnar.util.ClinicalDataXyPlotUtil.combineClinicalDataForXyPlot; + import java.util.*; import java.util.stream.Collectors; @@ -276,6 +277,33 @@ public List getMutationTypeCountsByGeneSpecific(StudyViewF return studyViewRepository.getMutationCountsByType(createContext(studyViewFilter), genomicDataFilters); } + @Cacheable( + cacheResolver = "staticRepositoryCacheOneResolver", + condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfilteredQuery(#studyViewFilter)" + ) + @Override + public List fetchClinicalDataForXyPlot( + StudyViewFilter studyViewFilter, + List attributeIds, + boolean shouldFilterNonEmptyClinicalData + ) { + List sampleClinicalDataList = this.getSampleClinicalData(studyViewFilter, attributeIds); + List patientClinicalDataList = this.getPatientClinicalData(studyViewFilter, attributeIds); + List samples = Collections.emptyList(); + + if (!patientClinicalDataList.isEmpty()) { + // fetch samples for the given study view filter. + // we need this to construct the complete patient to sample map. + samples = this.getFilteredSamples(studyViewFilter); + } + + return combineClinicalDataForXyPlot( + sampleClinicalDataList, + patientClinicalDataList, + samples, + shouldFilterNonEmptyClinicalData + ); + } private StudyViewFilterContext createContext(StudyViewFilter studyViewFilter) { List customSampleIdentifiers = customDataFilterUtil.extractCustomDataSamples(studyViewFilter); diff --git a/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java b/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java index bff2f6c1e58..39fc7001b8b 100644 --- a/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java +++ b/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java @@ -73,8 +73,6 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.cbioportal.web.columnar.util.ClinicalDataXyPlotUtil.fetchClinicalDataForXyPlot; - @InternalApi @RestController() @RequestMapping("/api") @@ -307,8 +305,7 @@ public ResponseEntity fetchClinicalDataDensityPlot( .yAxisLogScale(yAxisLogScale) .build(); - List combinedClinicalDataList = fetchClinicalDataForXyPlot( - studyViewColumnarService, + List combinedClinicalDataList = studyViewColumnarService.fetchClinicalDataForXyPlot( interceptedStudyViewFilter, List.of(xAxisAttributeId, yAxisAttributeId), false @@ -369,8 +366,7 @@ public ResponseEntity fetchClinicalDataViolinPlots( .ifPresent(f->interceptedStudyViewFilter.getClinicalDataFilters().remove(f)); } - List combinedClinicalDataList = fetchClinicalDataForXyPlot( - studyViewColumnarService, + List combinedClinicalDataList = studyViewColumnarService.fetchClinicalDataForXyPlot( interceptedStudyViewFilter, List.of(numericalAttributeId, categoricalAttributeId), true // filter out clinical data with empty attribute values due to Clickhouse migration diff --git a/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java b/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java index aee3a04a485..bf807fdbb41 100644 --- a/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java +++ b/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java @@ -12,15 +12,13 @@ import java.util.stream.Stream; public class ClinicalDataXyPlotUtil { - public static List fetchClinicalDataForXyPlot( - StudyViewColumnarService studyViewColumnarService, - StudyViewFilter studyViewFilter, - List attributeIds, + public static List combineClinicalDataForXyPlot( + List sampleClinicalDataList, + List patientClinicalDataList, + List samples, boolean shouldFilterNonEmptyClinicalData ) { List combinedClinicalDataList; - List sampleClinicalDataList = studyViewColumnarService.getSampleClinicalData(studyViewFilter, attributeIds); - List patientClinicalDataList = studyViewColumnarService.getPatientClinicalData(studyViewFilter, attributeIds); if (shouldFilterNonEmptyClinicalData) { sampleClinicalDataList = filterNonEmptyClinicalData(sampleClinicalDataList); @@ -30,10 +28,6 @@ public static List fetchClinicalDataForXyPlot( if (patientClinicalDataList.isEmpty()) { combinedClinicalDataList = sampleClinicalDataList; } else { - // fetch samples for the given study view filter. - // we need this to construct the complete patient to sample map. - List samples = studyViewColumnarService.getFilteredSamples(studyViewFilter); - combinedClinicalDataList = Stream.concat( sampleClinicalDataList.stream(), convertPatientClinicalDataToSampleClinicalData(patientClinicalDataList, samples).stream()