From 4864e861822a4709432565b84a829a8f6f777537 Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Wed, 18 Sep 2024 00:09:44 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=98=84=EC=9E=AC=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=EB=B6=80=ED=84=B0,=20=ED=95=9C=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=A0=84=EC=97=90=20=EC=83=9D=EC=84=B1=EB=90=9C=20?= =?UTF-8?q?score=EB=A5=BC=20=EC=82=AD=EC=A0=9C=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batch/grouprank/job/GroupRankRefreshJob.kt | 10 ++++++++-- .../domain/group/application/GroupUserScoreService.kt | 6 ++++++ .../group/infrastructure/GroupUserScoreRepository.kt | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/hero/alignlab/batch/grouprank/job/GroupRankRefreshJob.kt b/src/main/kotlin/com/hero/alignlab/batch/grouprank/job/GroupRankRefreshJob.kt index e444b96..bb3f313 100644 --- a/src/main/kotlin/com/hero/alignlab/batch/grouprank/job/GroupRankRefreshJob.kt +++ b/src/main/kotlin/com/hero/alignlab/batch/grouprank/job/GroupRankRefreshJob.kt @@ -31,11 +31,12 @@ class GroupRankRefreshJob( toModifiedAt = to ).associateBy { it.uid } + /** 랭크 업데이트 */ groupUserScoreService.findAllByUids(uids) .groupBy { groupUserScore -> groupUserScore.groupId } .forEach { (groupId, scores) -> - val groupUserScores = scores.map { groupUserScore -> - val score = counts[groupUserScore.uid]?.count?.toInt() ?: 0 + val groupUserScores = scores.mapNotNull { groupUserScore -> + val score = counts[groupUserScore.uid]?.count?.toInt() ?: return@mapNotNull null groupUserScore.apply { groupUserScore.score = score @@ -50,5 +51,10 @@ class GroupRankRefreshJob( wsHandler.launchSendEvent(groupUserScore.uid, groupUserScore.groupId) } } + + /** 1시간 전에 생성된 랭크 정보는 삭제 */ + txTemplates.writer.coExecute { + groupUserScoreService.deleteAllByModifiedAtBeforeSync(from) + } } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt index 1d21d03..93478e0 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime @Service class GroupUserScoreService( @@ -86,4 +87,9 @@ class GroupUserScoreService( groupUserScoreRepository.findAllByUidIn(uids) } } + + @Transactional + fun deleteAllByModifiedAtBeforeSync(modifiedAt: LocalDateTime) { + return groupUserScoreRepository.deleteAllByModifiedAtBefore(modifiedAt) + } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupUserScoreRepository.kt b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupUserScoreRepository.kt index f8cf405..f057b4d 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupUserScoreRepository.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupUserScoreRepository.kt @@ -4,6 +4,7 @@ import com.hero.alignlab.domain.group.domain.GroupUserScore import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime @Transactional(readOnly = true) @Repository @@ -17,4 +18,6 @@ interface GroupUserScoreRepository : JpaRepository { fun findAllByGroupIdAndUidIn(groupId: Long, uids: List): List fun findAllByUidIn(uids: List): List + + fun deleteAllByModifiedAtBefore(modifiedAt: LocalDateTime) }