Skip to content

Commit

Permalink
fix: 현재 시간으로부터, 한시간 전에 생성된 score를 삭제한다
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 17, 2024
1 parent 5d04c58 commit 4864e86
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,5 +51,10 @@ class GroupRankRefreshJob(
wsHandler.launchSendEvent(groupUserScore.uid, groupUserScore.groupId)
}
}

/** 1시간 전에 생성된 랭크 정보는 삭제 */
txTemplates.writer.coExecute {
groupUserScoreService.deleteAllByModifiedAtBeforeSync(from)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -86,4 +87,9 @@ class GroupUserScoreService(
groupUserScoreRepository.findAllByUidIn(uids)
}
}

@Transactional
fun deleteAllByModifiedAtBeforeSync(modifiedAt: LocalDateTime) {
return groupUserScoreRepository.deleteAllByModifiedAtBefore(modifiedAt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,4 +18,6 @@ interface GroupUserScoreRepository : JpaRepository<GroupUserScore, Long> {
fun findAllByGroupIdAndUidIn(groupId: Long, uids: List<Long>): List<GroupUserScore>

fun findAllByUidIn(uids: List<Long>): List<GroupUserScore>

fun deleteAllByModifiedAtBefore(modifiedAt: LocalDateTime)
}

0 comments on commit 4864e86

Please sign in to comment.