From d036b9e7b2d02698727918d210512be6202cb608 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Mon, 14 Oct 2024 17:02:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?DRAW-408=20fix:=20=EA=B7=B8=EB=A6=BC=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A7=81=EB=A0=AC=ED=99=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xorker/draw/mafia/dto/RedisMafiaPhase.kt | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/adapter/redis/src/main/kotlin/com/xorker/draw/mafia/dto/RedisMafiaPhase.kt b/adapter/redis/src/main/kotlin/com/xorker/draw/mafia/dto/RedisMafiaPhase.kt index 989a0fcd..40573ed7 100644 --- a/adapter/redis/src/main/kotlin/com/xorker/draw/mafia/dto/RedisMafiaPhase.kt +++ b/adapter/redis/src/main/kotlin/com/xorker/draw/mafia/dto/RedisMafiaPhase.kt @@ -12,7 +12,7 @@ data class RedisMafiaPhase @JsonCreator constructor( @JsonProperty("turnList") val turnList: List? = null, @JsonProperty("mafiaPlayer") val mafiaPlayer: RedisMafiaPlayer? = null, @JsonProperty("keyword") val keyword: RedisMafiaKeyword? = null, - @JsonProperty("drawData") val drawData: List>>? = null, + @JsonProperty("drawData") val drawData: List? = null, @JsonProperty("players") val players: Map>? = null, @JsonProperty("round") val round: Int? = null, @JsonProperty("turn") val turn: Int? = null, @@ -21,6 +21,11 @@ data class RedisMafiaPhase @JsonCreator constructor( @JsonProperty("mafiaWin") val isMafiaWin: Boolean? = null, ) +data class RedisDrawInfo @JsonCreator constructor( + @JsonProperty("userId") val userId: Long, + @JsonProperty("draw") val draw: Map, +) + enum class RedisMafiaPhaseStatus { WAIT, READY, @@ -102,7 +107,10 @@ fun MafiaPhase.toRedisMafiaPhase(): RedisMafiaPhase { category = keyword.category, ), drawData = drawData.map { pair -> - Pair(pair.first.value, pair.second) + RedisDrawInfo( + userId = pair.first.value, + draw = pair.second, + ) }, round = turnInfo.round, turn = turnInfo.turn, @@ -129,7 +137,10 @@ fun MafiaPhase.toRedisMafiaPhase(): RedisMafiaPhase { category = keyword.category, ), drawData = drawData.map { pair -> - Pair(pair.first.value, pair.second) + RedisDrawInfo( + userId = pair.first.value, + draw = pair.second, + ) }, players = serializePlayers(this.players), ) @@ -155,7 +166,10 @@ fun MafiaPhase.toRedisMafiaPhase(): RedisMafiaPhase { category = keyword.category, ), drawData = drawData.map { pair -> - Pair(pair.first.value, pair.second) + RedisDrawInfo( + userId = pair.first.value, + draw = pair.second, + ) }, answer = answer, ) @@ -181,7 +195,10 @@ fun MafiaPhase.toRedisMafiaPhase(): RedisMafiaPhase { category = keyword.category, ), drawData = drawData.map { pair -> - Pair(pair.first.value, pair.second) + RedisDrawInfo( + userId = pair.first.value, + draw = pair.second, + ) }, answer = answer, showAnswer = showAnswer, @@ -207,8 +224,8 @@ fun RedisMafiaPhase.toMafiaPhase(): MafiaPhase = when (status) { mafiaPlayer = mafiaPlayer!!.toPlayer(), keyword = keyword!!.toMafiaKeyword(), turnInfo = TurnInfo(round!!, turn!!), - drawData = drawData!!.map { pair -> - Pair(UserId(pair.first), pair.second) + drawData = drawData!!.map { item -> + Pair(UserId(item.userId), item.draw) }.toMutableList(), ) @@ -218,8 +235,8 @@ fun RedisMafiaPhase.toMafiaPhase(): MafiaPhase = when (status) { }, mafiaPlayer = mafiaPlayer!!.toPlayer(), keyword = keyword!!.toMafiaKeyword(), - drawData = drawData!!.map { pair -> - Pair(UserId(pair.first), pair.second) + drawData = drawData!!.map { item -> + Pair(UserId(item.userId), item.draw) }.toMutableList(), players = deserializePlayers(players!!), ) @@ -230,8 +247,8 @@ fun RedisMafiaPhase.toMafiaPhase(): MafiaPhase = when (status) { }, mafiaPlayer = mafiaPlayer!!.toPlayer(), keyword = keyword!!.toMafiaKeyword(), - drawData = drawData!!.map { pair -> - Pair(UserId(pair.first), pair.second) + drawData = drawData!!.map { item -> + Pair(UserId(item.userId), item.draw) }.toMutableList(), answer = answer, ) @@ -242,8 +259,8 @@ fun RedisMafiaPhase.toMafiaPhase(): MafiaPhase = when (status) { }, mafiaPlayer = mafiaPlayer!!.toPlayer(), keyword = keyword!!.toMafiaKeyword(), - drawData = drawData!!.map { pair -> - Pair(UserId(pair.first), pair.second) + drawData = drawData!!.map { item -> + Pair(UserId(item.userId), item.draw) }.toMutableList(), answer = answer, showAnswer = showAnswer!!, From 5b614ca0f9cdc403bf0cdc69585a87308a6a114b Mon Sep 17 00:00:00 2001 From: sunwoong Date: Mon, 14 Oct 2024 17:23:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?DRAW-375=20refactor:=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/com/xorker/draw/lock/RedisLockAdapter.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adapter/redis/src/main/kotlin/com/xorker/draw/lock/RedisLockAdapter.kt b/adapter/redis/src/main/kotlin/com/xorker/draw/lock/RedisLockAdapter.kt index 33441b76..e61e3025 100644 --- a/adapter/redis/src/main/kotlin/com/xorker/draw/lock/RedisLockAdapter.kt +++ b/adapter/redis/src/main/kotlin/com/xorker/draw/lock/RedisLockAdapter.kt @@ -14,7 +14,7 @@ internal class RedisLockAdapter( override fun lock(key: String) { while (getLock(key).not()) { try { - Thread.sleep(50) + Thread.sleep(SLEEP_TIME) } catch (e: InterruptedException) { throw UnSupportedException } @@ -28,10 +28,12 @@ internal class RedisLockAdapter( private fun getLock(key: String): Boolean { return redisTemplate .opsForValue() - .setIfAbsent(key + LOCK, LOCK, Duration.ofSeconds(1)) ?: throw NotFoundLockKeyException + .setIfAbsent(key + LOCK, LOCK, Duration.ofSeconds(LOCK_TIME)) ?: throw NotFoundLockKeyException } companion object { private const val LOCK = "lock" + private const val LOCK_TIME = 1L + private const val SLEEP_TIME = 50L } }