cache graphite coach pageview result for 10 seconds
This commit is contained in:
parent
26b5e490a9
commit
48890a09cd
|
@ -1,5 +1,6 @@
|
|||
package controllers
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import play.api.libs.ws.WS
|
||||
import play.api.mvc._, Results._
|
||||
import play.api.Play.current
|
||||
|
@ -13,20 +14,24 @@ object Monitor extends LilaController {
|
|||
private object path {
|
||||
val coachPageView = "servers.lichess.statsite.counts.main.counter.coach.page_view.profile"
|
||||
}
|
||||
private val coachPageViewCache = lila.memo.AsyncCache[lila.user.User.ID, Result](
|
||||
f = userId => WS.url(url).withQueryString(
|
||||
"format" -> "json",
|
||||
"target" -> s"""summarize(${path.coachPageView}.$userId,"1d","sum",false)""",
|
||||
// "target" -> s"""summarize(servers.lichess.statsite.counts.main.counter.insight.request,'1d','sum',false)""",
|
||||
"from" -> "-7d",
|
||||
"until" -> "now"
|
||||
).get() map {
|
||||
case res if res.status == 200 => Ok(res.body)
|
||||
case res =>
|
||||
lila.log("monitor").warn(s"coach ${res.status} ${res.body}")
|
||||
NotFound
|
||||
},
|
||||
timeToLive = 10 seconds
|
||||
)
|
||||
|
||||
def coachPageView = Secure(_.Coach) { ctx =>
|
||||
me =>
|
||||
WS.url(url).withQueryString(
|
||||
"format" -> "json",
|
||||
"target" -> s"""summarize(${path.coachPageView}.${me.id},"1h","sum",false)""",
|
||||
// "target" -> s"""summarize(servers.lichess.statsite.counts.main.counter.insight.request,'1d','sum',false)""",
|
||||
"from" -> "-7d",
|
||||
"until" -> "now"
|
||||
).get() map {
|
||||
case res if res.status == 200 => Ok(res.body)
|
||||
case res =>
|
||||
lila.log("monitor").warn(s"coach ${res.status} ${res.body}")
|
||||
NotFound
|
||||
}
|
||||
coachPageViewCache(me.id)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue