rubber duck tournament perfs by caching round tourney views for 2

seconds
This commit is contained in:
Thibault Duplessis 2015-06-10 00:39:00 +02:00
parent 5967f2a1ee
commit 50726b0cfe
3 changed files with 11 additions and 4 deletions

View file

@ -166,7 +166,7 @@ object Round extends LilaController with TheftPrevention {
private def myTour(tourId: Option[String])(implicit ctx: Context): Fu[Option[Tourney]] =
tourId ?? { tid =>
ctx.userId ?? { uid =>
TournamentRepo.byIdAndPlayerId(tid, uid)
Env.tournament.cached tour tid map (_ filter (_ contains uid))
}
}

View file

@ -58,8 +58,9 @@ object Tournament extends LilaController {
}
def gameStanding(id: String) = Open { implicit ctx =>
OptionOk(repo startedOrFinishedById id) { tour =>
html.tournament.gameStanding(tour, true)
env.cached tour id map {
case Some(t: lila.tournament.StartedOrFinished) => Ok(html.tournament.gameStanding(t, true))
case _ => NotFound
}
}

View file

@ -9,5 +9,11 @@ private[tournament] final class Cached {
timeToLive = 6 hours,
default = _ => none)
def name(id: String) = nameCache get id
def name(id: String): Option[String] = nameCache get id
private val staleViewCache = lila.memo.AsyncCache[String, Option[Tournament]](
(id: String) => TournamentRepo byId id,
timeToLive = 2 seconds)
def tour(id: String): Fu[Option[Tournament]] = staleViewCache(id)
}