12345678910111213141516171819202122232425262728293031323334353637 |
- package controllers
- import play.api.Play.current
- import play.api.mvc._
- import play.api.libs.json.Json
- import play.api.libs.concurrent._
- import java.util.concurrent.ThreadLocalRandom
- import scala.concurrent._
- import models._
- object Application extends Controller {
-
- private val TEST_DATABASE_ROWS = 10000
- private val dbEc = Akka.system.dispatchers.lookup("akka.actor.db")
- def json() = Action {
- Ok(Json.obj("message" -> "Hello World!"))
- }
- def db(queries: Int) = Action {
- import play.api.libs.concurrent.Execution.Implicits._
- Async {
- val random = ThreadLocalRandom.current()
- val worlds = Future.sequence( (for {
- _ <- 1 to queries
- } yield Future(World.findById(random.nextInt(TEST_DATABASE_ROWS) + 1))(dbEc)
- ).toList)
- worlds map {
- w => Ok(Json.toJson(w))
- }
- }
- }
- }
|