let lichess4545 stream games of 900 players

pull/6549/head
Thibault Duplessis 2020-05-03 09:16:21 -06:00
parent 007c2da245
commit ce660c7e1c
3 changed files with 18 additions and 9 deletions

View File

@ -271,11 +271,14 @@ final class Api(
}
}
def gamesByUsersStream = Action.async(parse.tolerantText) { implicit req =>
val userIds = req.body.split(',').view.take(300).map(lila.user.User.normalize).toSet
jsonStream {
env.game.gamesByUsersStream(userIds)
}.fuccess
def gamesByUsersStream = AnonOrScopedBody(parse.tolerantText)()(
anon = gamesByUsers(300),
scoped = req => u => gamesByUsers(if (u.id == "lichess4545") 900 else 500)(req)
)
private def gamesByUsers(max: Int)(req: Request[String]) = {
val userIds = req.body.split(',').view.take(max).map(lila.user.User.normalize).toSet
jsonStream(env.game.gamesByUsersStream(userIds))(req).fuccess
}
private val EventStreamConcurrencyLimitPerUser = new lila.memo.ConcurrencyLimit[String](

View File

@ -108,6 +108,14 @@ abstract private[controllers] class LilaController(val env: Env)
else anon(req)
}
protected def AnonOrScopedBody[A](parser: BodyParser[A])(selectors: OAuthScope.Selector*)(
anon: Request[A] => Fu[Result],
scoped: Request[A] => UserModel => Fu[Result]
): Action[A] = Action.async(parser) { req =>
if (HTTPRequest isOAuth req) ScopedBody(parser)(selectors)(scoped)(req)
else anon(req)
}
protected def AuthOrScoped(selectors: OAuthScope.Selector*)(
auth: Context => UserModel => Fu[Result],
scoped: RequestHeader => UserModel => Fu[Result]

View File

@ -15,7 +15,7 @@ final class GamesByUsersStream(gameRepo: lila.game.GameRepo)(implicit ec: scala.
private val chans = List("startGame", "finishGame")
private val blueprint = Source
.queue[Game](32, akka.stream.OverflowStrategy.dropHead)
.queue[Game](64, akka.stream.OverflowStrategy.dropHead)
.mapAsync(1)(gameRepo.withInitialFen)
.map(gameWithInitialFenWriter.writes)
@ -56,15 +56,13 @@ final class GamesByUsersStream(gameRepo: lila.game.GameRepo)(implicit ec: scala.
"rating" -> p.rating
)
.add("provisional" -> p.provisional)
.add("name" -> p.name)
})
)
.add("initialFen" -> initialFen)
.add("clock" -> g.clock.map { clock =>
Json.obj(
"initial" -> clock.limitSeconds,
"increment" -> clock.incrementSeconds,
"totalTime" -> clock.estimateTotalSeconds
"increment" -> clock.incrementSeconds
)
})
.add("daysPerTurn" -> g.daysPerTurn)