Skip to content

Commit

Permalink
fix: dataset result query only when needed (#126)
Browse files Browse the repository at this point in the history
We should query the s3 dataset bucket for results only when the dataset status is success
  • Loading branch information
alarv authored Nov 29, 2024
1 parent 49949ec commit 12be534
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/kotlin/org/jaqpot/api/entity/Dataset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ class Dataset(
var executedAt: OffsetDateTime? = null,

var executionFinishedAt: OffsetDateTime? = null
) : BaseEntity()
) : BaseEntity() {
fun shouldHaveResult(): Boolean {
return this.type == DatasetType.PREDICTION && this.status == DatasetStatus.SUCCESS
}
}


14 changes: 12 additions & 2 deletions src/main/kotlin/org/jaqpot/api/service/dataset/DatasetService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class DatasetService(

return dataset.map {
val input = storageService.readRawDatasetInput(it)
val result = storageService.readRawDatasetResult(it)
val result = if (it.shouldHaveResult()) {
storageService.readRawDatasetResult(it)
} else {
null
}
ResponseEntity.ok(it.toDto(input, result))
}
.orElse(ResponseEntity.notFound().build())
Expand All @@ -48,7 +52,13 @@ class DatasetService(
val datasets = datasetRepository.findAllByUserId(userId, pageable)

val inputsMap = storageService.readRawDatasetInputs(datasets.content)
val resultsMap = storageService.readRawDatasetResults(datasets.content)
val resultsMap: MutableMap<String, List<Any>?> =
datasets.content.associateBy { it.id.toString() }.mapValues { null }.toMutableMap()

val datasetsWithResults = datasets.content.filter { it.shouldHaveResult() }
storageService.readRawDatasetResults(datasetsWithResults).forEach {
resultsMap[it.key] = it.value
}

return ResponseEntity.ok().body(datasets.toGetDatasets200ResponseDto(inputsMap, resultsMap))
}
Expand Down

0 comments on commit 12be534

Please sign in to comment.