Skip to content

Commit aea722c

Browse files
committed
simplify update
1 parent a7714ad commit aea722c

File tree

1 file changed

+9
-13
lines changed
  • frameworks/Kotlin/ktor/ktor-r2dbc/src/main/kotlin/org/jetbrains/ktor/benchmarks

1 file changed

+9
-13
lines changed

frameworks/Kotlin/ktor/ktor-r2dbc/src/main/kotlin/org/jetbrains/ktor/benchmarks/Hello.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,15 @@ fun Application.main() {
134134
worldsUpdated.add(world)
135135
}
136136

137-
Mono.usingWhen(dbConnFactory.create(), { connection ->
138-
val statement = connection.createStatement(UPDATE_QUERY)
139-
worldsUpdated.forEach { world ->
140-
statement.bind("$1", world.randomNumber)
141-
statement.bind("$2", world.id)
142-
statement.add()
143-
}
144-
if (worldsUpdated.isNotEmpty()) {
145-
Mono.from(statement.execute())
146-
} else {
147-
Mono.empty()
148-
}
149-
}, Connection::close).awaitFirstOrNull()
137+
// Execute updates sequentially
138+
worldsUpdated.forEach { world ->
139+
Mono.usingWhen(dbConnFactory.create(), { connection ->
140+
Mono.from(connection.createStatement(UPDATE_QUERY)
141+
.bind("$1", world.randomNumber)
142+
.bind("$2", world.id)
143+
.execute())
144+
}, Connection::close).awaitFirstOrNull()
145+
}
150146

151147
call.respondText(json.encodeToString(worldsUpdated), ContentType.Application.Json)
152148
}

0 commit comments

Comments
 (0)