cloud upgrade live setting

pull/4722/head
Thibault Duplessis 2018-11-27 18:19:02 +07:00
parent 043ff67686
commit 3ba9fd900c
4 changed files with 17 additions and 5 deletions

View File

@ -228,4 +228,5 @@ object Env {
def streamer = lila.streamer.Env.current
def oAuth = lila.oauth.Env.current
def bot = lila.bot.Env.current
def evalCache = lila.evalCache.Env.current
}

View File

@ -19,7 +19,8 @@ object Dev extends LilaController {
Env.report.scoreThresholdSetting,
Env.api.cspEnabledSetting,
Env.api.wasmxEnabledSetting,
Env.streamer.alwaysFeaturedSetting
Env.streamer.alwaysFeaturedSetting,
Env.evalCache.upgradeEnabledSetting
)
def settings = Secure(_.Settings) { implicit ctx => me =>

View File

@ -4,6 +4,7 @@ import com.typesafe.config.Config
final class Env(
config: Config,
settingStore: lila.memo.SettingStore.Builder,
db: lila.db.Env,
system: akka.actor.ActorSystem,
asyncCache: lila.memo.AsyncCache.Builder
@ -14,7 +15,14 @@ final class Env(
private lazy val truster = new EvalCacheTruster
private lazy val upgrade = new EvalCacheUpgrade(
asyncCache = asyncCache
asyncCache = asyncCache,
enabled = upgradeEnabledSetting.get
)
val upgradeEnabledSetting = settingStore[Boolean](
"cloudUpgradeEnabled",
default = true,
text = "Enable cloud eval upgrade for everyone.".some
)
lazy val api = new EvalCacheApi(
@ -46,6 +54,7 @@ object Env {
lazy val current: Env = "evalCache" boot new Env(
config = lila.common.PlayApp loadConfig "evalCache",
settingStore = lila.memo.Env.current.settingStore,
db = lila.db.Env.current,
system = lila.common.PlayApp.system,
asyncCache = lila.memo.Env.current.asyncCache

View File

@ -12,14 +12,15 @@ import lila.socket.{ Socket, SocketMember }
* and listening to new evals stored.
*/
private final class EvalCacheUpgrade(
asyncCache: lila.memo.AsyncCache.Builder
asyncCache: lila.memo.AsyncCache.Builder,
enabled: () => Boolean
) {
import EvalCacheUpgrade._
private val members = AnyRefMap.empty[UidString, WatchingMember]
private val evals = AnyRefMap.empty[SetupId, Set[UidString]]
def register(uid: Socket.Uid, member: SocketMember, variant: Variant, fen: FEN, multiPv: Int, path: String): Unit = {
def register(uid: Socket.Uid, member: SocketMember, variant: Variant, fen: FEN, multiPv: Int, path: String): Unit = if (enabled()) {
members get uid.value foreach { wm =>
unregisterEval(wm.setupId, uid)
}
@ -31,7 +32,7 @@ private final class EvalCacheUpgrade(
println(evals, "evals")
}
def onEval(input: EvalCacheEntry.Input, uid: Socket.Uid): Unit = {
def onEval(input: EvalCacheEntry.Input, uid: Socket.Uid): Unit = if (enabled()) {
(1 to input.eval.multiPv) flatMap { multiPv =>
evals get makeSetupId(input.id.variant, input.fen, multiPv)
} foreach { uids =>