Skip to content

Commit

Permalink
Merge pull request #15973 from lenguyenthanh/game-ingestor
Browse files Browse the repository at this point in the history
Remove indexing games in favor of lila-search ingestor
  • Loading branch information
ornicar authored Aug 28, 2024
2 parents cca5468 + fbdd89d commit 65b28ea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 55 deletions.
5 changes: 1 addition & 4 deletions modules/analyse/src/main/Analyser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import monocle.syntax.all.*
import play.api.libs.json.*

import lila.common.Bus
import lila.core.game.InsertGame
import lila.core.misc.map.TellIfExists
import lila.tree.{ Analysis, ExportOptions, Tree }

Expand All @@ -28,9 +27,7 @@ final class Analyser(
_ <- gameRepo.setAnalysed(game.id, true)
_ <- analysisRepo.save(analysis)
_ <- sendAnalysisProgress(analysis, complete = true)
yield
Bus.publish(actorApi.AnalysisReady(game, analysis), "analysisReady")
Bus.publish(InsertGame(game), "gameSearchInsert")
yield Bus.publish(actorApi.AnalysisReady(game, analysis), "analysisReady")
}
case _ =>
analysisRepo.save(analysis) >>
Expand Down
1 change: 0 additions & 1 deletion modules/core/src/main/game/misc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ case class TvSelect(gameId: GameId, speed: Speed, channel: String, data: JsObjec
case class ChangeFeatured(mgs: JsObject)

case class StartGame(game: Game)
case class InsertGame(game: Game)
case class FinishGame(
game: Game,
// users and perfs BEFORE the game result is applied
Expand Down
9 changes: 2 additions & 7 deletions modules/gameSearch/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package lila.gameSearch

import com.softwaremill.macwire.*
import play.api.Configuration
import akka.stream.Materializer

import lila.common.autoconfig.{ *, given }
import lila.core.config.ConfigName
import lila.core.game.{ FinishGame, InsertGame }
import lila.core.game.FinishGame
import lila.search.*
import lila.search.client.SearchClient
import lila.search.spec.Query
Expand All @@ -23,7 +22,7 @@ final class Env(
gameRepo: lila.core.game.GameRepo,
userApi: lila.core.user.UserApi,
client: SearchClient
)(using Executor, Scheduler, Materializer, lila.core.i18n.Translator):
)(using Executor, lila.core.i18n.Translator):

private val config = appConfig.get[GameSearchConfig]("gameSearch")(AutoConfig.loader)

Expand All @@ -34,7 +33,3 @@ final class Env(
lazy val forms = wire[GameSearchForm]

lazy val userGameSearch = wire[UserGameSearch]

lila.common.Bus.subscribeFun("finishGame", "gameSearchInsert"):
case FinishGame(game, _) if !game.aborted => api.store(game)
case InsertGame(game) => api.store(game)
44 changes: 1 addition & 43 deletions modules/gameSearch/src/main/GameSearchApi.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lila.gameSearch

import akka.stream.scaladsl.*
import akka.stream.Materializer

import lila.search.client.SearchClient
import lila.search.spec.Query
Expand All @@ -11,7 +10,7 @@ final class GameSearchApi(
client: SearchClient,
gameRepo: lila.core.game.GameRepo,
userApi: lila.core.user.UserApi
)(using Executor, Scheduler, Materializer)
)(using Executor)
extends SearchReadApi[Game, Query.Game]:

def search(query: Query.Game, from: From, size: Size): Fu[List[Game]] =
Expand All @@ -36,44 +35,3 @@ final class GameSearchApi(
.map: res =>
Option.when(res.hitIds.nonEmpty && from < total.value):
(from + pageSize.value) -> res.hitIds.map(GameId.apply)

def store(game: Game) =
storable(game).so:
gameRepo.isAnalysed(game).flatMap { analysed =>
lila.common.LilaFuture
.retry(
() => client.storeGame(game.id.value, toDoc(game, analysed)),
delay = 20.seconds,
retries = 2,
logger.some
)
}

private def storable(game: Game) = game.finished

private def status(game: Game) = game.status match
case s if s.is(_.Timeout) => chess.Status.Resign
case s if s.is(_.NoStart) => chess.Status.Resign
case _ => game.status

private def toDoc(game: Game, analysed: Boolean): lila.search.spec.GameSource =
lila.search.spec.GameSource(
status = status(game).id,
turns = (game.ply.value + 1) / 2,
rated = game.rated,
perf = game.perfKey.id.value,
uids = game.userIds.some.filterNot(_.isEmpty).map(_.map(_.value)),
winner = game.winner.flatMap(_.userId).map(_.value),
loser = game.loser.flatMap(_.userId).map(_.value),
winnerColor = game.winner.fold(3)(_.color.fold(1, 2)),
averageRating = game.averageUsersRating,
ai = game.aiLevel,
date = lila.search.SearchDateTime.fromInstant(game.movedAt),
duration = game.durationSeconds, // for realtime games only
clockInit = game.clock.map(_.limitSeconds.value),
clockInc = game.clock.map(_.incrementSeconds.value),
analysed = analysed,
whiteUser = game.whitePlayer.userId.map(_.value),
blackUser = game.blackPlayer.userId.map(_.value),
source = game.source.map(_.id)
)

0 comments on commit 65b28ea

Please sign in to comment.