라이브 방 정보 처리 및 저장
- Redis -> Valkey로 이전되도록 수정
This commit is contained in:
@@ -20,6 +20,8 @@ import kr.co.vividnext.sodalive.live.roulette.RouletteItem
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import kr.co.vividnext.sodalive.v2.LiveRoomInfoRedisRepositoryV2
|
||||
import kr.co.vividnext.sodalive.v2.LiveRoomInfoV2
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
@@ -38,10 +40,27 @@ class RouletteService(
|
||||
private val memberRepository: MemberRepository,
|
||||
private val chargeRepository: ChargeRepository,
|
||||
private val roomInfoRepository: LiveRoomInfoRedisRepository,
|
||||
private val roomInfoRepositoryV2: LiveRoomInfoRedisRepositoryV2,
|
||||
private val useCanCalculateRepository: UseCanCalculateRepository
|
||||
) {
|
||||
private val tokenLocks: MutableMap<Long, ReentrantReadWriteLock> = mutableMapOf()
|
||||
|
||||
private fun getLiveRoomInfo(roomId: Long): LiveRoomInfoV2? {
|
||||
var roomInfoV2 = roomInfoRepositoryV2.findByIdOrNull(roomId)
|
||||
|
||||
if (roomInfoV2 == null) {
|
||||
val roomInfoV1 = roomInfoRepository.findByIdOrNull(roomId)
|
||||
|
||||
if (roomInfoV1 != null) {
|
||||
roomInfoV2 = roomInfoV1.convertRoomInfoV2()
|
||||
roomInfoRepositoryV2.save(roomInfoV2)
|
||||
roomInfoRepository.delete(roomInfoV1)
|
||||
}
|
||||
}
|
||||
|
||||
return roomInfoV2
|
||||
}
|
||||
|
||||
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetRouletteResponseV2> {
|
||||
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
|
||||
|
||||
@@ -158,7 +177,7 @@ class RouletteService(
|
||||
|
||||
val lock = getOrCreateLock(memberId = member.id!!)
|
||||
lock.write {
|
||||
val roomInfo = roomInfoRepository.findByIdOrNull(room.id!!)
|
||||
val roomInfo = getLiveRoomInfo(room.id!!)
|
||||
?: throw SodaException("해당하는 라이브의 정보가 없습니다.")
|
||||
|
||||
roomInfo.addRouletteMessage(
|
||||
@@ -167,7 +186,7 @@ class RouletteService(
|
||||
donationMessage = "[$result] 당첨!"
|
||||
)
|
||||
|
||||
roomInfoRepository.save(roomInfo)
|
||||
roomInfoRepositoryV2.save(roomInfo)
|
||||
}
|
||||
|
||||
return SpinRouletteResponse(can = roulette.can, result = result, items = itemList)
|
||||
|
Reference in New Issue
Block a user