rubber duck tournament perfs by caching round tourney views for 2
seconds
This commit is contained in:
parent
5967f2a1ee
commit
50726b0cfe
|
@ -166,7 +166,7 @@ object Round extends LilaController with TheftPrevention {
|
||||||
private def myTour(tourId: Option[String])(implicit ctx: Context): Fu[Option[Tourney]] =
|
private def myTour(tourId: Option[String])(implicit ctx: Context): Fu[Option[Tourney]] =
|
||||||
tourId ?? { tid =>
|
tourId ?? { tid =>
|
||||||
ctx.userId ?? { uid =>
|
ctx.userId ?? { uid =>
|
||||||
TournamentRepo.byIdAndPlayerId(tid, uid)
|
Env.tournament.cached tour tid map (_ filter (_ contains uid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,9 @@ object Tournament extends LilaController {
|
||||||
}
|
}
|
||||||
|
|
||||||
def gameStanding(id: String) = Open { implicit ctx =>
|
def gameStanding(id: String) = Open { implicit ctx =>
|
||||||
OptionOk(repo startedOrFinishedById id) { tour =>
|
env.cached tour id map {
|
||||||
html.tournament.gameStanding(tour, true)
|
case Some(t: lila.tournament.StartedOrFinished) => Ok(html.tournament.gameStanding(t, true))
|
||||||
|
case _ => NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,5 +9,11 @@ private[tournament] final class Cached {
|
||||||
timeToLive = 6 hours,
|
timeToLive = 6 hours,
|
||||||
default = _ => none)
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue