fix homepage cache
parent
d4a3507070
commit
a3bce798fb
|
@ -11,6 +11,12 @@ import views._
|
|||
final class KeyPages(env: Env)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
def home(status: Results.Status)(implicit ctx: Context): Fu[Result] =
|
||||
homeHtml
|
||||
.dmap { html =>
|
||||
env.lilaCookie.ensure(ctx.req)(status(html))
|
||||
}
|
||||
|
||||
def homeHtml(implicit ctx: Context): Fu[Frag] =
|
||||
env
|
||||
.preloader(
|
||||
posts = env.forum.recent(ctx.me, env.team.cached.teamIdsList).nevermind,
|
||||
|
@ -24,9 +30,6 @@ final class KeyPages(env: Env)(implicit ec: scala.concurrent.ExecutionContext) {
|
|||
html.lobby.home(h)
|
||||
}
|
||||
}
|
||||
.dmap { (html: Frag) =>
|
||||
env.lilaCookie.ensure(ctx.req)(status(html))
|
||||
}
|
||||
|
||||
def notFound(ctx: Context): Result = {
|
||||
Results.NotFound(html.base.notFound()(ctx))
|
||||
|
|
|
@ -105,13 +105,6 @@ abstract private[controllers] class LilaController(val env: Env)
|
|||
reqToCtx(req) flatMap f
|
||||
}
|
||||
|
||||
protected def OpenCache(f: Context => Fu[Result]): Action[Unit] =
|
||||
Action.async(parse.empty) { req =>
|
||||
env.pageCache(req) { () =>
|
||||
handleOpen(f, req)
|
||||
}
|
||||
}
|
||||
|
||||
protected def AnonOrScoped(selectors: OAuthScope.Selector*)(
|
||||
anon: RequestHeader => Fu[Result],
|
||||
scoped: RequestHeader => UserModel => Fu[Result]
|
||||
|
|
|
@ -18,10 +18,14 @@ final class Lobby(
|
|||
)
|
||||
|
||||
def home =
|
||||
OpenCache { implicit ctx =>
|
||||
Open { implicit ctx =>
|
||||
pageHit
|
||||
negotiate(
|
||||
html = keyPages.home(Results.Ok).dmap(NoCache),
|
||||
html = env.pageCache { () =>
|
||||
keyPages.homeHtml.dmap { html =>
|
||||
NoCache(Ok(html))
|
||||
}
|
||||
} dmap env.lilaCookie.ensure(ctx.req),
|
||||
api = _ =>
|
||||
fuccess {
|
||||
val expiration = 60 * 60 * 24 * 7 // set to one hour, one week before changing the pool config
|
||||
|
|
|
@ -6,24 +6,21 @@ import play.api.mvc._
|
|||
import scala.concurrent.duration._
|
||||
|
||||
import lila.common.HTTPRequest
|
||||
import lila.api.Context
|
||||
import lila.i18n.I18nLangPicker
|
||||
|
||||
final class PageCache(security: lila.security.SecurityApi, cacheApi: lila.memo.CacheApi) {
|
||||
|
||||
private val cache = cacheApi.notLoading[String, Result](32, "pageCache") {
|
||||
private val cache = cacheApi.notLoading[String, Result](16, "pageCache") {
|
||||
_.expireAfterWrite(1.seconds).buildAsync()
|
||||
}
|
||||
|
||||
def apply(req: RequestHeader)(compute: () => Fu[Result]): Fu[Result] =
|
||||
qualifiesWithLang(req).fold(compute()) { lang =>
|
||||
cache.getFuture(s"${HTTPRequest actionName req}($lang)", _ => compute())
|
||||
}
|
||||
|
||||
private def qualifiesWithLang(req: RequestHeader): Option[String] =
|
||||
security.reqSessionId(req).isEmpty ?? {
|
||||
val lang = I18nLangPicker(req).language
|
||||
langs(lang) option lang
|
||||
}
|
||||
def apply(compute: () => Fu[Result])(implicit ctx: Context): Fu[Result] =
|
||||
if (ctx.isAnon && langs(ctx.lang.language)) {
|
||||
val cacheKey = s"${HTTPRequest actionName ctx.req}(${ctx.lang.language})"
|
||||
cache.getFuture(cacheKey, _ => compute())
|
||||
} else
|
||||
compute()
|
||||
|
||||
private val langs =
|
||||
Set("en", "ru", "tr", "de", "es", "fr", "pt", "it", "pl", "ar", "fa", "id", "nl", "nb", "sv")
|
||||
|
|
Loading…
Reference in New Issue