Browse Source

Scala http4s: fix batch update (#4886)

Ondra Pelech 6 years ago
parent
commit
d62c14733b
1 changed files with 2 additions and 1 deletions
  1. 2 1
      frameworks/Scala/http4s/src/main/scala/WebServer.scala

+ 2 - 1
frameworks/Scala/http4s/src/main/scala/WebServer.scala

@@ -101,7 +101,8 @@ object WebServer extends IOApp with Http4sDsl[IO] {
   // this uses a batch update SQL call.
   def updateWorlds(xa: Transactor[IO], newWorlds: List[World]): IO[Int] = {
     val sql = "update World set randomNumber = ? where id = ?"
-    val update = Update[(Int, Int)](sql).updateMany(newWorlds.map(w => (w.randomNumber, w.id)))
+    // Reason for sorting: https://github.com/TechEmpower/FrameworkBenchmarks/pull/4214#issuecomment-489358881
+    val update = Update[(Int, Int)](sql).updateMany(newWorlds.sortBy(_.id).map(w => (w.randomNumber, w.id)))
     update.transact(xa)
   }