relocate tournament caches
This commit is contained in:
parent
e3bf3278a3
commit
4549ec92ca
|
@ -30,7 +30,7 @@ object Lobby extends LilaController {
|
|||
def renderHome(status: Results.Status)(implicit ctx: Context): Fu[Result] =
|
||||
Env.current.preloader(
|
||||
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds),
|
||||
tours = Env.tournament promotable true,
|
||||
tours = Env.tournament.cached promotable true,
|
||||
simuls = Env.simul allCreatedFeaturable true
|
||||
) map (html.lobby.home.apply _).tupled map { template =>
|
||||
// the session cookie is required for anon lobby filter storage
|
||||
|
|
|
@ -20,7 +20,7 @@ object Tournament extends LilaController {
|
|||
private def tournamentNotFound(implicit ctx: Context) = NotFound(html.tournament.notFound())
|
||||
|
||||
val home = Open { implicit ctx =>
|
||||
env.fetchVisibleTournaments() zip repo.scheduledDedup zip UserRepo.allSortToints(10) map {
|
||||
env.api.fetchVisibleTournaments zip repo.scheduledDedup zip UserRepo.allSortToints(10) map {
|
||||
case ((visible@VisibleTournaments(created, started, finished), scheduled), leaderboard) =>
|
||||
Ok(html.tournament.home(created, started, finished, scheduled, leaderboard, env scheduleJsonView visible))
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ object Tournament extends LilaController {
|
|||
}
|
||||
|
||||
val homeReload = Open { implicit ctx =>
|
||||
env.fetchVisibleTournaments() map {
|
||||
env.api.fetchVisibleTournaments map {
|
||||
case VisibleTournaments(created, started, finished) =>
|
||||
Ok(html.tournament.homeInner(created, started, finished))
|
||||
}
|
||||
|
|
|
@ -2,12 +2,23 @@ package lila.tournament
|
|||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
private[tournament] final class Cached {
|
||||
import lila.memo._
|
||||
|
||||
private val nameCache = lila.memo.MixedCache[String, Option[String]](
|
||||
private[tournament] final class Cached(
|
||||
createdTtl: FiniteDuration) {
|
||||
|
||||
private val nameCache = MixedCache[String, Option[String]](
|
||||
((id: String) => TournamentRepo byId id map2 { (tour: Tournament) => tour.fullName }),
|
||||
timeToLive = 6 hours,
|
||||
default = _ => none)
|
||||
|
||||
def name(id: String): Option[String] = nameCache get id
|
||||
|
||||
val allCreatedSorted = AsyncCache.single(
|
||||
TournamentRepo.publicCreatedSorted,
|
||||
timeToLive = createdTtl)
|
||||
|
||||
val promotable = AsyncCache.single(
|
||||
TournamentRepo.promotable,
|
||||
timeToLive = createdTtl)
|
||||
}
|
||||
|
|
|
@ -47,7 +47,10 @@ final class Env(
|
|||
|
||||
lazy val forms = new DataForm
|
||||
|
||||
lazy val cached = new Cached(CreatedCacheTtl)
|
||||
|
||||
lazy val api = new TournamentApi(
|
||||
cached = cached,
|
||||
system = system,
|
||||
sequencers = sequencerMap,
|
||||
autoPairing = autoPairing,
|
||||
|
@ -71,8 +74,6 @@ final class Env(
|
|||
mongoCache = mongoCache,
|
||||
ttl = LeaderboardCacheTtl)
|
||||
|
||||
lazy val cached = new Cached
|
||||
|
||||
lazy val jsonView = new JsonView(lightUser)
|
||||
|
||||
lazy val scheduleJsonView = new ScheduleJsonView(lightUser)
|
||||
|
@ -106,17 +107,6 @@ final class Env(
|
|||
def version(tourId: String): Fu[Int] =
|
||||
socketHub ? Ask(tourId, GetVersion) mapTo manifest[Int]
|
||||
|
||||
val allCreatedSorted =
|
||||
lila.memo.AsyncCache.single(TournamentRepo.publicCreatedSorted, timeToLive = CreatedCacheTtl)
|
||||
|
||||
val promotable =
|
||||
lila.memo.AsyncCache.single(TournamentRepo.promotable, timeToLive = CreatedCacheTtl)
|
||||
|
||||
val fetchVisibleTournaments: () => Fu[VisibleTournaments] = () =>
|
||||
allCreatedSorted(true) zip TournamentRepo.publicStarted zip TournamentRepo.finished(10) map {
|
||||
case ((created, started), finished) => VisibleTournaments(created, started, finished)
|
||||
}
|
||||
|
||||
private lazy val autoPairing = new AutoPairing(
|
||||
roundMap = roundMap,
|
||||
system = system,
|
||||
|
|
|
@ -23,6 +23,7 @@ import lila.user.{ User, UserRepo }
|
|||
import makeTimeout.short
|
||||
|
||||
private[tournament] final class TournamentApi(
|
||||
cached: Cached,
|
||||
system: ActorSystem,
|
||||
sequencers: ActorRef,
|
||||
autoPairing: AutoPairing,
|
||||
|
@ -230,6 +231,14 @@ private[tournament] final class TournamentApi(
|
|||
}
|
||||
}
|
||||
|
||||
def fetchVisibleTournaments: Fu[VisibleTournaments] =
|
||||
cached.allCreatedSorted(true) zip
|
||||
TournamentRepo.publicStarted zip
|
||||
TournamentRepo.finished(10) map {
|
||||
case ((created, started), finished) =>
|
||||
VisibleTournaments(created, started, finished)
|
||||
}
|
||||
|
||||
private def sequence(tourId: String)(work: => Funit) {
|
||||
sequencers ! Tell(tourId, Sequencer work work)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue