upgrade proxied game when analysis completes
parent
9a92893361
commit
519608d819
|
@ -35,7 +35,9 @@ final class Fishnet(env: Env) extends LilaController(env) {
|
|||
// case WeakAnalysis => fuccess(Left(UnprocessableEntity("Not enough nodes per move")))
|
||||
case e => fuccess(Left(InternalServerError(e.getMessage)))
|
||||
}, {
|
||||
case _: PostAnalysisResult.Complete => acquireNext
|
||||
case PostAnalysisResult.Complete(analysis) =>
|
||||
env.round.proxyRepo.updateIfPresent(analysis.id)(_.withMetadata(_.copy(analysed = true)))
|
||||
acquireNext
|
||||
case _: PostAnalysisResult.Partial => fuccess(Left(NoContent))
|
||||
case PostAnalysisResult.UnusedPartial => fuccess(Left(NoContent))
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ final class Round(
|
|||
(pov.game.simulId ?? env.simul.repo.find) zip
|
||||
getPlayerChat(pov.game, tour.map(_.tour)) zip
|
||||
(ctx.noBlind ?? env.game.crosstableApi
|
||||
.withMatchup(pov.game)) zip // probably what raises page mean time?
|
||||
.withMatchup(pov.game)) zip
|
||||
(pov.game.isSwitchable ?? otherPovs(pov.game)) zip
|
||||
env.bookmark.api.exists(pov.game, ctx.me) zip
|
||||
env.api.roundApi.player(pov, lila.api.Mobile.Api.currentVersion) map {
|
||||
|
|
|
@ -193,7 +193,7 @@ final class User(
|
|||
env.game.gameRepo
|
||||
.lastPlayed(user)
|
||||
.flatMap(_ ?? { p =>
|
||||
env.round.proxyRepo.updateIfPresent(p) dmap some
|
||||
env.round.proxyRepo.upgradeIfPresent(p) dmap some
|
||||
})
|
||||
|
||||
private val UserGamesRateLimitPerIP = new lila.memo.RateLimit[IpAddress](
|
||||
|
@ -221,7 +221,7 @@ final class User(
|
|||
me = ctx.me,
|
||||
page = page
|
||||
)(ctx.body)
|
||||
pag <- pagFromDb.mapFutureResults(env.round.proxyRepo.updateIfPresent)
|
||||
pag <- pagFromDb.mapFutureResults(env.round.proxyRepo.upgradeIfPresent)
|
||||
_ <- env.tournament.cached.nameCache preloadMany pag.currentPageResults.flatMap(_.tournamentId)
|
||||
_ <- env.user.lightUserApi preloadMany pag.currentPageResults.flatMap(_.userIds)
|
||||
} yield pag
|
||||
|
|
|
@ -73,7 +73,7 @@ final class UserAnalysis(
|
|||
|
||||
def game(id: String, color: String) = Open { implicit ctx =>
|
||||
OptionFuResult(env.game.gameRepo game id) { g =>
|
||||
env.round.proxyRepo updateIfPresent g flatMap { game =>
|
||||
env.round.proxyRepo upgradeIfPresent g flatMap { game =>
|
||||
val pov = Pov(game, chess.Color(color == "white"))
|
||||
negotiate(
|
||||
html =
|
||||
|
|
|
@ -109,7 +109,7 @@ object GameFilterMenu {
|
|||
)(page)
|
||||
case All =>
|
||||
std(Query started user.id) flatMap {
|
||||
_.mapFutureResults(gameProxyRepo.updateIfPresent)
|
||||
_.mapFutureResults(gameProxyRepo.upgradeIfPresent)
|
||||
}
|
||||
case Me => std(Query.opponents(user, me | user))
|
||||
case Rated => std(Query rated user.id)
|
||||
|
@ -123,7 +123,7 @@ object GameFilterMenu {
|
|||
nb = nb
|
||||
)(page)
|
||||
.flatMap {
|
||||
_.mapFutureResults(gameProxyRepo.updateIfPresent)
|
||||
_.mapFutureResults(gameProxyRepo.upgradeIfPresent)
|
||||
}
|
||||
.addEffect { p =>
|
||||
p.currentPageResults.filter(_.finishedOrAborted) foreach gameRepo.unsetPlayingUids
|
||||
|
|
|
@ -6,6 +6,7 @@ import lila.common.Bus
|
|||
import lila.hub.actorApi.slack.{ Victory, Warning }
|
||||
import lila.memo.ExpireSetMemo
|
||||
|
||||
// slack alerts for lichess analysis nodes
|
||||
final private class MainWatcher(
|
||||
repo: FishnetRepo
|
||||
)(implicit ec: scala.concurrent.ExecutionContext, system: akka.actor.ActorSystem) {
|
||||
|
|
|
@ -575,6 +575,8 @@ case class Game(
|
|||
def playerPov(p: Player) = pov(p.color)
|
||||
def loserPov = loser map playerPov
|
||||
|
||||
def withMetadata(f: Metadata => Metadata) = copy(metadata = f(metadata))
|
||||
|
||||
override def toString = s"""Game($id)"""
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,10 @@ final private class GameProxy(
|
|||
else fuccess(scheduleFlushProgress)
|
||||
}
|
||||
|
||||
def update(f: Game => Game): Funit = withGame { g =>
|
||||
fuccess(set(f(g)))
|
||||
}
|
||||
|
||||
private[round] def saveAndFlush(progress: Progress): Funit = {
|
||||
set(progress.game)
|
||||
dirtyProgress = dirtyProgress.fold(progress.dropEvents)(_ withGame progress.game).some
|
||||
|
|
|
@ -22,12 +22,16 @@ final class GameProxyRepo(
|
|||
|
||||
def gameIfPresent(gameId: Game.ID): Fu[Option[Game]] = roundSocket gameIfPresent gameId
|
||||
|
||||
def updateIfPresent(game: Game): Fu[Game] =
|
||||
// get the proxied version of the game
|
||||
def upgradeIfPresent(game: Game): Fu[Game] =
|
||||
if (game.finishedOrAborted) fuccess(game)
|
||||
else roundSocket updateIfPresent game
|
||||
else roundSocket upgradeIfPresent game
|
||||
|
||||
def updateIfPresent(pov: Pov): Fu[Pov] =
|
||||
updateIfPresent(pov.game).dmap(_ pov pov.color)
|
||||
def upgradeIfPresent(pov: Pov): Fu[Pov] =
|
||||
upgradeIfPresent(pov.game).dmap(_ pov pov.color)
|
||||
|
||||
// update the proxied game
|
||||
def updateIfPresent = roundSocket.updateIfPresent _
|
||||
|
||||
def povIfPresent(gameId: Game.ID, color: chess.Color): Fu[Option[Pov]] =
|
||||
gameIfPresent(gameId) dmap2 { Pov(_, color) }
|
||||
|
|
|
@ -98,7 +98,8 @@ final private[round] class RoundDuct(
|
|||
private val whitePlayer = new Player(White)
|
||||
private val blackPlayer = new Player(Black)
|
||||
|
||||
def getGame: Fu[Option[Game]] = proxy.game
|
||||
def getGame: Fu[Option[Game]] = proxy.game
|
||||
def updateGame(f: Game => Game): Funit = proxy update f
|
||||
|
||||
val process: Duct.ReceiveAsync = {
|
||||
|
||||
|
|
|
@ -51,9 +51,16 @@ final class RoundSocket(
|
|||
|
||||
def gameIfPresent(gameId: Game.ID): Fu[Option[Game]] = rounds.getIfPresent(gameId).??(_.getGame)
|
||||
|
||||
def updateIfPresent(game: Game): Fu[Game] =
|
||||
// get the proxied version of the game
|
||||
def upgradeIfPresent(game: Game): Fu[Game] =
|
||||
rounds.getIfPresent(game.id).fold(fuccess(game))(_.getGame.dmap(_ | game))
|
||||
|
||||
// update the proxied game
|
||||
def updateIfPresent(gameId: Game.ID)(f: Game => Game): Funit =
|
||||
rounds.getIfPresent(gameId) ?? {
|
||||
_ updateGame f
|
||||
}
|
||||
|
||||
val rounds = new DuctConcMap[RoundDuct](
|
||||
mkDuct = id => {
|
||||
val proxy = new GameProxy(id, proxyDependencies)
|
||||
|
|
Loading…
Reference in New Issue