feat: NCS-82 add Swiss-system tournament module #55
@@ -201,26 +201,22 @@ class AccountService:
|
||||
|
||||
@Transactional
|
||||
def createOfficialBotAccount(botName: String): Either[AccountError, OfficialBotAccount] =
|
||||
val id = UUID.randomUUID()
|
||||
val bot = new OfficialBotAccount()
|
||||
bot.id = id
|
||||
bot.name = botName
|
||||
bot.createdAt = Instant.now()
|
||||
bot.token = generateBotToken(id, botName)
|
||||
officialBotAccountRepository.persist(bot)
|
||||
bot.token = generateBotToken(bot.id, botName)
|
||||
|
|
||||
Right(bot)
|
||||
|
||||
@Transactional
|
||||
def syncOfficialBots(botNames: List[String]): Unit =
|
||||
botNames.foreach { name =>
|
||||
if officialBotAccountRepository.findByName(name).isEmpty then
|
||||
val id = UUID.randomUUID()
|
||||
val bot = new OfficialBotAccount()
|
||||
bot.id = id
|
||||
bot.name = name
|
||||
bot.createdAt = Instant.now()
|
||||
bot.token = generateBotToken(id, name)
|
||||
officialBotAccountRepository.persist(bot)
|
||||
bot.token = generateBotToken(bot.id, name)
|
||||
log.infof("Auto-registered official bot: %s", name)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user
Same two-persist pattern. The root cause is that bot.id is not available before the first persist(). Either use a pre-assigned UUID (@Id with UUID.randomUUID() before persist) or derive the token from a field that doesn't require a DB round-trip. Two flushes per creation is a correctness risk under failure: if the second persist fails, the entity exists without a valid token.