diff --git a/app/controllers/Lobby.scala b/app/controllers/Lobby.scala index ad299bc73a..6c03e5c51a 100644 --- a/app/controllers/Lobby.scala +++ b/app/controllers/Lobby.scala @@ -29,7 +29,7 @@ object Lobby extends LilaController { def renderHome[A](status: Results.Status)(implicit ctx: Context): Fu[SimpleResult] = Env.current.preloader( posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds.apply), - tours = TournamentRepo.allCreatedSorted, + tours = Env.tournament.allCreatedSorted(true), filter = Env.setup.filter ).map(_.fold(Redirect(_), { case (preload, entries, posts, tours, featured, leaderboard, progress, puzzle) => diff --git a/app/controllers/Tournament.scala b/app/controllers/Tournament.scala index 760f042b38..933b91e3ed 100644 --- a/app/controllers/Tournament.scala +++ b/app/controllers/Tournament.scala @@ -40,7 +40,7 @@ object Tournament extends LilaController { } private def fetchTournaments = - repo.allCreatedSorted zip repo.started zip repo.finished(20) + env allCreatedSorted true zip repo.started zip repo.finished(20) def show(id: String) = Open { implicit ctx => repo byId id flatMap { diff --git a/modules/tournament/src/main/Env.scala b/modules/tournament/src/main/Env.scala index 3e552bd706..50e7c6d8d5 100644 --- a/modules/tournament/src/main/Env.scala +++ b/modules/tournament/src/main/Env.scala @@ -25,6 +25,7 @@ final class Env( private val settings = new { val CollectionTournament = config getString "collection.tournament" val MessageTtl = config duration "message.ttl" + val CreatedCacheTtl = config duration "created.cache.ttl" val UidTimeout = config duration "uid.timeout" val SocketTimeout = config duration "socket.timeout" val SocketName = config getString "socket.name" @@ -75,6 +76,9 @@ final class Env( def version(tourId: String): Fu[Int] = socketHub ? Ask(tourId, GetVersion) mapTo manifest[Int] + val allCreatedSorted = + lila.memo.AsyncCache.single(TournamentRepo.allCreatedSorted, timeToLive = CreatedCacheTtl) + def cli = new lila.common.Cli { import tube.tournamentTube def process = { @@ -95,7 +99,7 @@ final class Env( organizer -> actorApi.StartedTournaments } - scheduler.message(1 minute) { + scheduler.message(5 minutes) { tournamentScheduler -> actorApi.ScheduleNow } tournamentScheduler ! actorApi.ScheduleNow