Skip to content

Commit

Permalink
fix(sql): Properly apply maxResults in listObjectVersions()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajordens committed Jul 8, 2019
1 parent b7b2dbb commit 35c293f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import java.time.Clock
import com.netflix.spinnaker.front50.model.ObjectType.*
import com.netflix.spinnaker.front50.model.sql.*
import com.netflix.spinnaker.kork.sql.config.SqlRetryProperties
import java.util.ArrayList

class SqlStorageService(
private val objectMapper: ObjectMapper,
Expand Down Expand Up @@ -173,14 +174,19 @@ class SqlStorageService(
override fun <T : Timestamped> listObjectVersions(objectType: ObjectType,
objectKey: String,
maxResults: Int): List<T> {
val bodies = jooq.withRetry(sqlRetryProperties.reads) { ctx ->
if (maxResults == 1) {
// will throw NotFoundException if object does not exist
return listOf(loadObject(objectType, objectKey))
}

val bodies = jooq.withRetry(sqlRetryProperties.reads) { ctx ->
if (definitionsByType[objectType]!!.supportsHistory) {
ctx
.select(field("body", String::class.java))
.from(definitionsByType[objectType]!!.historyTableName)
.where(DSL.field("id", String::class.java).eq(objectKey))
.orderBy(DSL.field("recorded_at").desc())
.limit(maxResults)
.fetch()
.getValues(field("body", String::class.java))
} else {
Expand Down

0 comments on commit 35c293f

Please sign in to comment.