don't display empty tournaments

This commit is contained in:
Thibault Duplessis 2015-06-27 16:46:49 +02:00
parent 4e75e669bc
commit 464c9be4e3
3 changed files with 6 additions and 2 deletions

View file

@ -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))
}

View file

@ -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)

View file

@ -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 !=)