only show simuls where host is currently online

pull/6333/head
Thibault Duplessis 2020-04-06 17:51:05 -05:00
parent cf1ef4be1c
commit 7cc13fe175
6 changed files with 11 additions and 26 deletions

View File

@ -44,7 +44,7 @@ final class Simul(
}
private def fetchSimuls =
env.simul.allCreated.get({}) zip env.simul.repo.allStarted zip env.simul.repo.allFinished(30)
env.simul.allCreatedFeaturable.get({}) zip env.simul.repo.allStarted zip env.simul.repo.allFinished(30)
def show(id: String) = Open { implicit ctx =>
env.simul.repo find id flatMap {

View File

@ -44,7 +44,7 @@ final class PublicChat(
}
private def fetchVisibleSimuls: Fu[List[Simul]] = {
simulEnv.allCreated.get({}) zip
simulEnv.allCreatedFeaturable.get({}) zip
simulEnv.repo.allStarted zip
simulEnv.repo.allFinished(3) map {
case ((created, started), finished) =>

View File

@ -46,11 +46,6 @@ final class Env(
val isHosting = new lila.round.IsSimulHost(u => api.currentHostIds dmap (_ contains u))
val allCreated = cacheApi.unit[List[Simul]] {
_.refreshAfterWrite(3 seconds)
.buildAsyncFuture(_ => repo.allCreated)
}
val allCreatedFeaturable = cacheApi.unit[List[Simul]] {
_.refreshAfterWrite(3 seconds)
.buildAsyncFuture(_ => repo.allCreatedFeaturable)

View File

@ -123,8 +123,6 @@ case class Simul(
def setPairingHostColor(gameId: String, hostColor: chess.Color) =
updatePairing(gameId, _.copy(hostColor = hostColor))
def isNotBrandNew = createdAt isBefore DateTime.now.minusSeconds(10)
private def Created(s: => Simul): Simul = if (isCreated) s else this
def spotlightable =

View File

@ -59,9 +59,6 @@ final class SimulApi(
text = setup.text,
team = setup.team
)
repo.createdByHostId(me.id) foreach {
_.filter(_.isNotBrandNew).map(_.id).foreach(abort)
}
(repo create simul) >>- publish() >>- {
timeline ! (Propagate(SimulCreate(me.id, simul.id, simul.fullName)) toFollowersOf me.id)
} inject simul
@ -245,7 +242,7 @@ final class SimulApi(
private val siteMessage = SendToFlag("simul", Json.obj("t" -> "reload"))
private val debouncer = system.actorOf(Props(new Debouncer(5 seconds, { (_: Debouncer.Nothing) =>
Bus.publish(siteMessage, "sendToFlag")
repo.allCreated foreach { simuls =>
repo.allCreatedFeaturable foreach { simuls =>
renderer.actor ? actorApi.SimulTable(simuls) map {
case view: String => Bus.publish(ReloadSimuls(view), "lobbySocket")
}

View File

@ -64,25 +64,22 @@ final private[simul] class SimulRepo(simulColl: Coll)(implicit ec: scala.concurr
def exists(id: Simul.ID): Fu[Boolean] =
simulColl.exists($id(id))
def createdByHostId(hostId: String): Fu[List[Simul]] =
simulColl.ext.find(createdSelect ++ $doc("hostId" -> hostId)).list[Simul]()
def findStarted(id: Simul.ID): Fu[Option[Simul]] =
find(id) map (_ filter (_.isStarted))
def findCreated(id: Simul.ID): Fu[Option[Simul]] =
find(id) map (_ filter (_.isCreated))
def allCreated: Fu[List[Simul]] =
simulColl.ext.find(createdSelect).sort(createdSort).list[Simul]()
def allCreatedFeaturable: Fu[List[Simul]] =
simulColl.ext
.find(
createdSelect ++ $doc("createdAt" $gte DateTime.now.minusMinutes(15))
)
.find(createdSelect ++ $doc("hostSeenAt" $gte DateTime.now.minusSeconds(12)))
.sort(createdSort)
.list[Simul]()
.list[Simul]() map {
_.foldLeft(List.empty[Simul]) {
case (acc, sim) if acc.exists(_.hostId == sim.hostId) => acc
case (acc, sim) => sim :: acc
}.reverse
}
def allStarted: Fu[List[Simul]] =
simulColl.ext
@ -94,9 +91,7 @@ final private[simul] class SimulRepo(simulColl: Coll)(implicit ec: scala.concurr
def allFinished(max: Int): Fu[List[Simul]] =
simulColl.ext
.find(
finishedSelect
)
.find(finishedSelect)
.sort(createdSort)
.list[Simul](max)