better use round proxy

team-info-lookup
Thibault Duplessis 2019-08-20 10:30:09 +02:00
parent dd5f6e4789
commit 58ef918df2
8 changed files with 24 additions and 21 deletions

View File

@ -280,7 +280,7 @@ object Round extends LilaController with TheftPrevention {
}
def resign(fullId: String) = Open { implicit ctx =>
OptionFuRedirect(GameRepo pov fullId) { pov =>
OptionFuRedirect(proxyPov(fullId)) { pov =>
if (isTheft(pov)) {
controllerLogger.warn(s"theft resign $fullId ${HTTPRequest.lastRemoteAddress(ctx.req)}")
fuccess(routes.Lobby.home)

View File

@ -112,11 +112,6 @@ lazy val evaluation = module("evaluation", Seq(
libraryDependencies ++= provided(play.api, reactivemongo.driver)
)
// lazy val simulation = module("simulation", Seq(
// common, hub, socket, game, tv, round, setup)).settings(
// libraryDependencies ++= provided(play.api, reactivemongo.driver)
// )
lazy val common = module("common", Seq()).settings(
libraryDependencies ++= provided(play.api, play.test, reactivemongo.driver, kamon.core, scalatags) ++ Seq(scaffeine)
)

View File

@ -8,14 +8,15 @@ import scala.concurrent.duration._
import lila.common.Tellable
import lila.db.dsl._
import lila.game.{ GameRepo, Pov }
import lila.game.{ Game, Pov }
import lila.hub.actorApi.round.IsOnGame
import makeTimeout.short
private final class CorresAlarm(
system: akka.actor.ActorSystem,
coll: Coll,
socketMap: SocketMap
socketMap: SocketMap,
proxyGame: Game.ID => Fu[Option[Game]]
) {
private case class Alarm(
@ -37,7 +38,7 @@ private final class CorresAlarm(
system.lilaBus.subscribeFun('moveEventCorres) {
case lila.hub.actorApi.round.CorresMoveEvent(move, _, _, alarmable, _) if alarmable =>
GameRepo game move.gameId flatMap {
proxyGame(move.gameId) flatMap {
_ ?? { game =>
game.bothPlayersHaveMoved ?? {
game.playableCorrespondenceClock ?? { clock =>
@ -63,7 +64,7 @@ private final class CorresAlarm(
)).cursor[Alarm](ReadPreference.secondaryPreferred)
.enumerator(100, Cursor.ContOnError())
.|>>>(Iteratee.foldM[Alarm, Int](0) {
case (count, alarm) => GameRepo.game(alarm._id).flatMap {
case (count, alarm) => proxyGame(alarm._id).flatMap {
_ ?? { game =>
val pov = Pov(game, game.turnColor)
socketMap.ask[Boolean](pov.gameId)(IsOnGame(pov.color, _)) addEffect {

View File

@ -253,7 +253,7 @@ final class Env(
name = "titivate"
)
private val corresAlarm = new CorresAlarm(system, db(CollectionAlarm), socketMap)
private val corresAlarm = new CorresAlarm(system, db(CollectionAlarm), socketMap, proxy.game _)
private lazy val takebacker = new Takebacker(
messenger = messenger,

View File

@ -119,13 +119,14 @@ private[round] final class Finisher(
updateCountAndPerfs(finish) map { ratingDiffs =>
message foreach { messenger.system(g, _) }
GameRepo game g.id foreach { newGame =>
newGame foreach proxy.setFinishedGame
bus.publish(finish.copy(game = newGame | g), 'finishGame)
}
prog.events :+ lila.game.Event.EndData(g, ratingDiffs)
}
}
}
} >>- proxy.reloadFinishedGame
}
private def updateCountAndPerfs(finish: FinishGame): Fu[Option[RatingDiffs]] =
(!finish.isVsSelf && !finish.game.aborted) ?? {

View File

@ -37,10 +37,10 @@ private final class GameProxy(
cache = fuccess(game.some)
}
private[round] def reloadFinishedGame: Unit = {
private[round] def setFinishedGame(game: Game): Unit = {
scheduledFlush.cancel()
set(game)
dirtyProgress = none
cache = fetch
}
// convenience helpers
@ -84,7 +84,7 @@ object GameProxy {
type Save = Progress => Funit
private val scheduleDelay = 10.seconds
private val scheduleDelay = 15.seconds
private val emptyCancellable = new Cancellable {
def cancel() = true

View File

@ -4,7 +4,8 @@ import akka.actor._
import com.typesafe.config.Config
import scala.concurrent.duration._
import lila.hub.{ Duct, DuctMap, TrouperMap }
import lila.game.Game
import lila.hub.{ Duct, DuctMap }
import lila.socket.History
import lila.socket.Socket.{ GetVersion, SocketVersion }
@ -17,7 +18,8 @@ final class Env(
lightUser: lila.common.LightUser.Getter,
onGameStart: String => Unit,
isOnline: String => Boolean,
asyncCache: lila.memo.AsyncCache.Builder
asyncCache: lila.memo.AsyncCache.Builder,
proxyGame: Game.ID => Fu[Option[Game]]
) {
private val CollectionSimul = config getString "collection.simul"
@ -43,7 +45,7 @@ final class Env(
asyncCache = asyncCache
)
lazy val jsonView = new JsonView(lightUser)
lazy val jsonView = new JsonView(lightUser, proxyGame)
private val socketMap: SocketMap = lila.socket.SocketMap[Socket](
system = system,
@ -144,6 +146,7 @@ object Env {
lightUser = lila.user.Env.current.lightUser,
onGameStart = lila.game.Env.current.onStart,
isOnline = lila.user.Env.current.isOnline,
asyncCache = lila.memo.Env.current.asyncCache
asyncCache = lila.memo.Env.current.asyncCache,
proxyGame = lila.round.Env.current.proxy.game _
)
}

View File

@ -6,11 +6,14 @@ import lila.common.LightUser
import lila.game.{ Game, GameRepo }
import lila.user.User
final class JsonView(getLightUser: LightUser.Getter) {
final class JsonView(
getLightUser: LightUser.Getter,
proxyGame: Game.ID => Fu[Option[Game]]
) {
private def fetchGames(simul: Simul) =
if (simul.isFinished) GameRepo gamesFromSecondary simul.gameIds
else GameRepo gamesFromPrimary simul.gameIds
else simul.gameIds.map(proxyGame).sequenceFu.map(_.flatten)
def apply(simul: Simul, team: Option[SimulTeam]): Fu[JsObject] = for {
games <- fetchGames(simul)