Skip to content

Commit

Permalink
Cache slower study view requests at Controller level
Browse files Browse the repository at this point in the history
- some requests take a while even when cached at the mapper level
because they have a significant amount of service level logic
- to combat this, we cache these requests at the controller level
when the study view filter is in its default state
  • Loading branch information
Luke-Sikina committed Oct 8, 2021
1 parent f802e2a commit 2a09433
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 13 deletions.
2 changes: 2 additions & 0 deletions log.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*** Couldn't find a suitable DSN, Sentry operations will do nothing! See documentation: https://docs.sentry.io/clients/java/ ***
No 'stacktrace.app.packages' was configured, this option is highly recommended as it affects stacktrace grouping and display on Sentry. See documentation: https://docs.sentry.io/clients/java/config/#in-application-stack-frames
58 changes: 51 additions & 7 deletions web/src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ public ResponseEntity<List<AlterationCountByGene>> fetchMutatedGenes(
@ApiIgnore // 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 = instance.cachedFetchMutatedGenes(interceptedStudyViewFilter, singleStudyUnfiltered);
return new ResponseEntity<>(alterationCountByGenes, HttpStatus.OK);
}

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

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
Expand All @@ -171,7 +182,7 @@ public ResponseEntity<List<AlterationCountByGene>> fetchMutatedGenes(
studyViewFilterUtil.extractStudyAndSampleIds(sampleIdentifiers, studyIds, sampleIds);
alterationCountByGenes = studyViewService.getMutationAlterationCountByGenes(studyIds, sampleIds, annotationFilters);
}
return new ResponseEntity<>(alterationCountByGenes, HttpStatus.OK);
return alterationCountByGenes;
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
Expand All @@ -187,8 +198,21 @@ public ResponseEntity<List<AlterationCountByGene>> fetchStructuralVariantGenes(
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) throws StudyNotFoundException {

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

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

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<AlterationCountByGene> alterationCountByGenes = new ArrayList<>();
if(CollectionUtils.isNotEmpty(sampleIdentifiers)) {
Expand All @@ -197,10 +221,10 @@ public ResponseEntity<List<AlterationCountByGene>> fetchStructuralVariantGenes(
studyViewFilterUtil.extractStudyAndSampleIds(sampleIdentifiers, studyIds, sampleIds);
alterationCountByGenes = studyViewService.getStructuralVariantAlterationCountByGenes(studyIds, sampleIds, annotationFilters);
}
return new ResponseEntity<>(alterationCountByGenes, HttpStatus.OK);
return alterationCountByGenes;
}


@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/cna-genes/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -213,9 +237,18 @@ public ResponseEntity<List<CopyNumberCountByGene>> fetchCNAGenes(
@ApiIgnore // 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 = instance.cacheableFetchCNAGenes(interceptedStudyViewFilter, singleStudyUnfiltered);
return new ResponseEntity<>(copyNumberCountByGenes, HttpStatus.OK);
}

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

List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<CopyNumberCountByGene> copyNumberCountByGenes = new ArrayList<>();
if(CollectionUtils.isNotEmpty(sampleIdentifiers)) {
Expand All @@ -224,7 +257,7 @@ public ResponseEntity<List<CopyNumberCountByGene>> fetchCNAGenes(
studyViewFilterUtil.extractStudyAndSampleIds(sampleIdentifiers, studyIds, sampleIds);
copyNumberCountByGenes = studyViewService.getCNAAlterationCountByGenes(studyIds, sampleIds, alterationFilter);
}
return new ResponseEntity<>(copyNumberCountByGenes, HttpStatus.OK);
return copyNumberCountByGenes;
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
Expand Down Expand Up @@ -265,6 +298,17 @@ public List<GenomicDataCount> fetchMolecularProfileSampleCounts(
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiIgnore // 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) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
return cacheableFetchMolecularProfileSampleCounts(interceptedStudyViewFilter, singleStudyUnfiltered);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
)
public List<GenomicDataCount> cacheableFetchMolecularProfileSampleCounts(
StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<GenomicDataCount> genomicDataCounts = new ArrayList<>();
if(CollectionUtils.isNotEmpty(sampleIdentifiers)) {
Expand All @@ -275,7 +319,7 @@ public List<GenomicDataCount> fetchMolecularProfileSampleCounts(
}
return genomicDataCounts;
}

private static boolean isLogScalePossibleForAttribute(String clinicalAttributeId) {
return clinicalAttributeId.equals("MUTATION_COUNT");
}
Expand Down
49 changes: 43 additions & 6 deletions web/src/main/java/org/cbioportal/web/TreatmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.cbioportal.web.util.StudyViewFilterApplier;
import org.cbioportal.web.util.StudyViewFilterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,6 +22,7 @@
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.PostConstruct;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.ArrayList;
Expand All @@ -31,6 +34,16 @@
@Validated
@Api(tags = "Treatments", description = " ")
public class TreatmentController {
@Autowired
private ApplicationContext applicationContext;
TreatmentController instance;
@PostConstruct
private void init() {
instance = applicationContext.getBean(TreatmentController.class);
}

@Autowired
private StudyViewFilterUtil studyViewFilterUtil;
@Autowired
private StudyViewFilterUtil filterUtil;

Expand Down Expand Up @@ -61,14 +74,26 @@ public ResponseEntity<List<PatientTreatmentRow>> getAllPatientTreatments(
@Valid
@RequestAttribute(required = false, value = "interceptedStudyViewFilter")
StudyViewFilter interceptedStudyViewFilter
) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<PatientTreatmentRow> treatments =
instance.cachableGetAllPatientTreatments(tier, interceptedStudyViewFilter, singleStudyUnfiltered);
return new ResponseEntity<>(treatments, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
)
public List<PatientTreatmentRow> cachableGetAllPatientTreatments(
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<String> sampleIds = new ArrayList<>();
List<String> studyIds = new ArrayList<>();
filterUtil.extractStudyAndSampleIds(sampleIdentifiers, studyIds, sampleIds);

List<PatientTreatmentRow> treatments = treatmentService.getAllPatientTreatmentRows(sampleIds, studyIds, tier);
return new ResponseEntity<>(treatments, HttpStatus.OK);

return treatmentService.getAllPatientTreatmentRows(sampleIds, studyIds, tier);
}


Expand All @@ -93,14 +118,26 @@ public ResponseEntity<List<SampleTreatmentRow>> getAllSampleTreatments(
@Valid
@RequestAttribute(required = false, value = "interceptedStudyViewFilter")
StudyViewFilter interceptedStudyViewFilter
) {
boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(interceptedStudyViewFilter);
List<SampleTreatmentRow> treatments =
instance.cacheableGetAllSampleTreatments(tier, interceptedStudyViewFilter, singleStudyUnfiltered);
return new ResponseEntity<>(treatments, HttpStatus.OK);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered"
)
public List<SampleTreatmentRow> cacheableGetAllSampleTreatments(
ClinicalEventKeyCode tier, StudyViewFilter interceptedStudyViewFilter, boolean singleStudyUnfiltered
) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(interceptedStudyViewFilter);
List<String> sampleIds = new ArrayList<>();
List<String> studyIds = new ArrayList<>();
filterUtil.extractStudyAndSampleIds(sampleIdentifiers, studyIds, sampleIds);

List<SampleTreatmentRow> treatments = treatmentService.getAllSampleTreatmentRows(sampleIds, studyIds, tier);
return new ResponseEntity<>(treatments, HttpStatus.OK);

return treatmentService.getAllSampleTreatmentRows(sampleIds, studyIds, tier);
}

@PreAuthorize("hasPermission(#studyIds, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
Expand Down

0 comments on commit 2a09433

Please sign in to comment.