the daily puzzle cache was instanciated at every homepage hit!

This commit is contained in:
Thibault Duplessis 2017-01-29 11:48:03 +01:00
parent 334b72de71
commit ee7fb75db3
4 changed files with 7 additions and 9 deletions

View file

@ -53,9 +53,7 @@ final class Env(
asyncCache = Env.memo.asyncCache)
private def tryDailyPuzzle(): Fu[Option[lila.puzzle.DailyPuzzle]] =
scala.concurrent.Future {
Env.puzzle.daily()
}.flatMap(identity).withTimeoutDefault(100 millis, none)(system) recover {
Env.puzzle.daily.get.withTimeoutDefault(100 millis, none)(system) recover {
case e: Exception =>
lila.log("preloader").warn("daily puzzle", e)
none
@ -64,7 +62,8 @@ final class Env(
system.actorOf(Props(new actor.Renderer), name = RendererName)
lila.log.boot.info("Preloading modules")
lila.common.Chronometer.syncEffect(List(Env.socket,
lila.common.Chronometer.syncEffect(List(
Env.socket,
Env.site,
Env.tournament,
Env.lobby,

View file

@ -38,7 +38,7 @@ object Puzzle extends LilaController {
}
def daily = Open { implicit ctx =>
OptionFuResult(env.daily() flatMap {
OptionFuResult(env.daily.get flatMap {
_.map(_.id) ?? env.api.puzzle.find
}) { puzzle =>
negotiate(
@ -214,7 +214,7 @@ object Puzzle extends LilaController {
}
def frame = Open { implicit ctx =>
OptionOk(env.daily()) { daily =>
OptionOk(env.daily.get) { daily =>
html.puzzle.embed(daily)
}
}

View file

@ -21,7 +21,7 @@ private[puzzle] final class Daily(
f = find,
expireAfter = _.ExpireAfterWrite(10 minutes))
def apply: Fu[Option[DailyPuzzle]] = cache.get
def get: Fu[Option[DailyPuzzle]] = cache.get
private def find: Fu[Option[DailyPuzzle]] = (findCurrent orElse findNew) recover {
case e: Exception =>

View file

@ -60,8 +60,7 @@ final class Env(
puzzleColl,
renderer,
asyncCache = asyncCache,
system.scheduler
).apply _
system.scheduler)
def cli = new lila.common.Cli {
def process = {