Skip to content

Commit

Permalink
Cache treatment endpoints (#10282)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalletlak authored Jul 26, 2023
1 parent 4ac327b commit 0ed4759
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions web/src/main/java/org/cbioportal/web/TreatmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

@PublicApi
@RestController
Expand Down Expand Up @@ -151,12 +152,18 @@ public ResponseEntity<Boolean> getContainsTreatmentData(
@ApiParam(required = true, value = "List of Study IDs")
@Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE)
@RequestBody
List<String> studyIds
Set<String> studyIds
) {
Boolean containsTreatmentData = treatmentService.containsTreatmentData(studyIds, tier);
Boolean containsTreatmentData = instance.cacheableGetContainsTreatmentData(studyIds, tier);
return new ResponseEntity<>(containsTreatmentData, HttpStatus.OK);
}

// Caching enabled for any number of studies as the requests contains only studyIds and the response is a boolean
@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
public Boolean cacheableGetContainsTreatmentData(Set<String> studyIds, ClinicalEventKeyCode tier) {
return treatmentService.containsTreatmentData(new ArrayList<>(studyIds), tier);
}

@PreAuthorize("hasPermission(#studyIds, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/treatments/display-sample", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Should sample level treatments be displayed")
Expand All @@ -168,9 +175,14 @@ public ResponseEntity<Boolean> getContainsSampleTreatmentData(
@ApiParam(required = true, value = "List of Study IDs")
@Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE)
@RequestBody
List<String> studyIds
Set<String> studyIds
) {
Boolean containsTreatmentData = treatmentService.containsSampleTreatmentData(studyIds, tier);
Boolean containsTreatmentData = instance.cacheableGetContainsSampleTreatmentData(studyIds, tier);
return new ResponseEntity<>(containsTreatmentData, HttpStatus.OK);
}

@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
public Boolean cacheableGetContainsSampleTreatmentData(Set<String> studyIds, ClinicalEventKeyCode tier) {
return treatmentService.containsSampleTreatmentData(new ArrayList<>(studyIds), tier);
}
}

0 comments on commit 0ed4759

Please sign in to comment.