diff --git a/app/controllers/Relay.scala b/app/controllers/Relay.scala index a220d9530a..b0c7376308 100644 --- a/app/controllers/Relay.scala +++ b/app/controllers/Relay.scala @@ -16,7 +16,7 @@ object Relay extends LilaController { private def relayNotFound(implicit ctx: Context) = NotFound(html.relay.notFound()) val index = Open { implicit ctx => - env.repo recent 50 flatMap { relays => + env.repo recentNonEmpty 50 flatMap { relays => env.contentApi byRelays relays map { contents => Ok(html.relay.home(relays, contents)) } diff --git a/modules/relay/src/main/Cached.scala b/modules/relay/src/main/Cached.scala index d2a4ec0bd6..d25d0eae3e 100644 --- a/modules/relay/src/main/Cached.scala +++ b/modules/relay/src/main/Cached.scala @@ -12,7 +12,7 @@ private[relay] final class Cached(repo: RelayRepo) { def name(id: String) = nameCache get id private val miniStartedCache = lila.memo.AsyncCache.single[List[Relay.Mini]]( - repo.started map2 Relay.Mini.apply, + repo.startedNonEmpty map2 Relay.Mini.apply, // repo.recent(3) map2 Relay.Mini.apply, timeToLive = 10 seconds) diff --git a/modules/relay/src/main/RelayRepo.scala b/modules/relay/src/main/RelayRepo.scala index 71f6799130..f6e4cf4d31 100644 --- a/modules/relay/src/main/RelayRepo.scala +++ b/modules/relay/src/main/RelayRepo.scala @@ -14,6 +14,7 @@ final class RelayRepo(coll: Coll) { private def selectName(name: String) = BSONDocument("name" -> name) private val selectStarted = BSONDocument("status" -> Relay.Status.Started.id) private val selectRecent = BSONDocument("date" -> BSONDocument("$gt" -> DateTime.now.minusWeeks(2))) + private val selectNonEmpty = BSONDocument("games.0.id" -> BSONDocument("$exists" -> true)) private val sortRecent = BSONDocument("date" -> -1) def byId(id: String): Fu[Option[Relay]] = coll.find(selectId(id)).one[Relay] @@ -22,9 +23,12 @@ final class RelayRepo(coll: Coll) { coll.find(selectName(name) ++ selectRecent).one[Relay] def started: Fu[List[Relay]] = coll.find(selectStarted).cursor[Relay].collect[List]() + def startedNonEmpty: Fu[List[Relay]] = coll.find(selectStarted ++ selectNonEmpty).cursor[Relay].collect[List]() def recent(nb: Int): Fu[List[Relay]] = coll.find(BSONDocument()).sort(sortRecent).cursor[Relay].collect[List](nb) + def recentNonEmpty(nb: Int): Fu[List[Relay]] = + coll.find(selectNonEmpty).sort(sortRecent).cursor[Relay].collect[List](nb) def exists(id: String): Fu[Boolean] = coll.db command Count(coll.name, selectId(id).some) map (0 !=)