From 19599f28c9e6ff15696b4af17b45b1528a71317f Mon Sep 17 00:00:00 2001 From: Onur Sumer Date: Fri, 10 Jan 2025 15:21:21 -0500 Subject: [PATCH] make xy plot data cacheable (#11278) --- .../service/StudyViewColumnarService.java | 2 ++ .../impl/StudyViewColumnarServiceImpl.java | 30 +++++++++++++++++++ .../StudyViewColumnStoreController.java | 8 ++--- .../columnar/util/ClinicalDataXyPlotUtil.java | 16 +++------- 4 files changed, 38 insertions(+), 18 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 a048d860656..f827a33411f 100644 --- a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java @@ -34,7 +34,10 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; +import static org.cbioportal.web.columnar.util.ClinicalDataXyPlotUtil.combineClinicalDataForXyPlot; + import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -273,6 +276,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..58b2d1e9c4e 100644 --- a/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java +++ b/src/main/java/org/cbioportal/web/columnar/util/ClinicalDataXyPlotUtil.java @@ -2,8 +2,6 @@ import org.cbioportal.model.ClinicalData; import org.cbioportal.model.Sample; -import org.cbioportal.service.StudyViewColumnarService; -import org.cbioportal.web.parameter.StudyViewFilter; import java.util.ArrayList; import java.util.List; @@ -12,15 +10,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 +26,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()