feat(challenge): replace scala.util.Random with ThreadLocalRandom for better performance and add native build configuration
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
quarkus.native.additional-build-args=\
|
||||
--initialize-at-run-time=org.redisson,\
|
||||
--initialize-at-run-time=io.netty
|
||||
|
||||
%native.quarkus.arc.exclude-types=org.redisson.*
|
||||
+1
-3
@@ -40,13 +40,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection
|
||||
classOf[DeclineRequest],
|
||||
classOf[ChallengeListDto],
|
||||
classOf[ErrorDto],
|
||||
classOf[ChallengeStatus],
|
||||
classOf[ChallengeColor],
|
||||
classOf[DeclineReason],
|
||||
classOf[CorePlayerInfo],
|
||||
classOf[CoreTimeControl],
|
||||
classOf[CoreCreateGameRequest],
|
||||
classOf[CoreGameResponse],
|
||||
classOf[OfficialChallengeResponse],
|
||||
),
|
||||
)
|
||||
class NativeReflectionConfig
|
||||
|
||||
@@ -6,7 +6,8 @@ import jakarta.enterprise.inject.Produces
|
||||
import jakarta.inject.Inject
|
||||
import org.redisson.Redisson
|
||||
import org.redisson.api.RedissonClient
|
||||
import org.redisson.config.Config
|
||||
import org.redisson.config.{Config, TransportMode}
|
||||
|
||||
import scala.compiletime.uninitialized
|
||||
|
||||
@ApplicationScoped
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ import org.jboss.logging.Logger
|
||||
import scala.compiletime.uninitialized
|
||||
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
@Path("/api/challenge/official")
|
||||
@ApplicationScoped
|
||||
@@ -68,7 +69,7 @@ class OfficialChallengeResource:
|
||||
val userIsWhite = playerColor match
|
||||
case "white" => true
|
||||
case "black" => false
|
||||
case _ => scala.util.Random.nextBoolean()
|
||||
case _ => ThreadLocalRandom.current().nextBoolean()
|
||||
val (white, black, botColor) =
|
||||
if userIsWhite then
|
||||
(CorePlayerInfo(user.id.toString, user.username), CorePlayerInfo(bot.id.toString, bot.name), "black")
|
||||
|
||||
@@ -29,6 +29,7 @@ import scala.compiletime.uninitialized
|
||||
import java.time.Instant
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
@ApplicationScoped
|
||||
class ChallengeService:
|
||||
@@ -158,7 +159,7 @@ class ChallengeService:
|
||||
case ChallengeColor.White => (challenger, destUser)
|
||||
case ChallengeColor.Black => (destUser, challenger)
|
||||
case ChallengeColor.Random =>
|
||||
if scala.util.Random.nextBoolean() then (challenger, destUser) else (destUser, challenger)
|
||||
if ThreadLocalRandom.current().nextBoolean() then (challenger, destUser) else (destUser, challenger)
|
||||
|
||||
private def buildTimeControl(challenge: Challenge): Option[CoreTimeControl] =
|
||||
challenge.timeControlType match
|
||||
|
||||
Reference in New Issue
Block a user