forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to lila.web.SocketTest, add distribution live setting
- Loading branch information
Showing
12 changed files
with
51 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package lila.web | ||
|
||
import play.api.libs.json.* | ||
|
||
import lila.db.JSON | ||
import lila.core.config.NetConfig | ||
import lila.ui.Context | ||
|
||
final class SocketTest( | ||
resultsDb: lila.db.AsyncCollFailingSilently, | ||
settingStore: lila.memo.SettingStore.Builder | ||
)(using Executor): | ||
|
||
val distributionSetting = settingStore[Int]( | ||
"socketTestDistribution", | ||
default = 0, | ||
text = "Participates to socket test if userId.hashCode % distribution == 0".some | ||
) | ||
|
||
def put(results: JsObject) = resultsDb: coll => | ||
coll.insert.one(JSON.bdoc(results)).void | ||
|
||
def isTestRunning() = distributionSetting.get() > 0 | ||
|
||
def isUserInTestBucket()(using ctx: Context) = | ||
isTestRunning() && | ||
ctx.pref.usingAltSocket.isEmpty && | ||
ctx.userId.exists(_.value.hashCode % distributionSetting.get() == 0) | ||
|
||
def socketEndpoints(net: NetConfig)(using ctx: Context): List[String] = | ||
ctx.pref.usingAltSocket.match | ||
case Some(true) => net.socketAlts | ||
case Some(false) => net.socketDomains | ||
case _ if isUserInTestBucket() => net.socketDomains.head :: net.socketAlts.headOption.toList | ||
case _ => net.socketDomains |