forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnv.scala
40 lines (29 loc) · 1.18 KB
/
Env.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package lila.gameSearch
import com.softwaremill.macwire.*
import lila.common.autoconfig.{ *, given }
import play.api.Configuration
import lila.game.actorApi.{ FinishGame, InsertGame }
import lila.search.*
import lila.common.config.*
@Module
private class GameSearchConfig(
@ConfigName("index") val indexName: String,
@ConfigName("paginator.max_per_page") val paginatorMaxPerPage: MaxPerPage,
@ConfigName("actor.name") val actorName: String
)
@Module
final class Env(
appConfig: Configuration,
gameRepo: lila.game.GameRepo,
makeClient: Index => ESClient
)(using Executor, Scheduler):
private val config = appConfig.get[GameSearchConfig]("gameSearch")(AutoConfig.loader)
private lazy val client = makeClient(Index(config.indexName))
lazy val api = wire[GameSearchApi]
lazy val paginator = PaginatorBuilder[lila.game.Game, Query](api, config.paginatorMaxPerPage)
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).unit
case InsertGame(game) => api.store(game).unit
}