Application.scala 869 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package controllers
  2. import play.api.Play.current
  3. import play.api.mvc._
  4. import play.api.libs.json.Json
  5. import play.api.libs.concurrent._
  6. import java.util.concurrent.ThreadLocalRandom
  7. import scala.concurrent._
  8. import models._
  9. object Application extends Controller {
  10. private val TEST_DATABASE_ROWS = 10000
  11. private val dbEc = Akka.system.dispatchers.lookup("akka.actor.db")
  12. def json() = Action {
  13. Ok(Json.obj("message" -> "Hello World!"))
  14. }
  15. def db(queries: Int) = Action {
  16. import play.api.libs.concurrent.Execution.Implicits._
  17. Async {
  18. val random = ThreadLocalRandom.current()
  19. val worlds = Future.sequence( (for {
  20. _ <- 1 to queries
  21. } yield Future(World.findById(random.nextInt(TEST_DATABASE_ROWS) + 1))(dbEc)
  22. ).toList)
  23. worlds map {
  24. w => Ok(Json.toJson(w))
  25. }
  26. }
  27. }
  28. }