Skip to content

Commit

Permalink
fix: 그룹 유저 스코어를 수정 시간대를 기준으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 16, 2024
1 parent 5d90d80 commit 544c9ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ class GroupRankRefreshJob(

val uids = groupUsers.map { it.uid }

val counts = poseSnapshotService.countByUidsAndCreatedAtBetween(
val counts = poseSnapshotService.countByUidsAndModifiedAtBetween(
uids = uids,
fromCreatedAt = from,
toCreatedAt = to
fromModifiedAt = from,
toModifiedAt = to
).associateBy { it.uid }

groupUserScoreService.findAllByUids(uids)
.groupBy { it.groupId }
.forEach { (key, value) ->
val groupUserScores = value.mapNotNull {
val score = counts[it.uid]?.count?.toInt() ?: return@mapNotNull null
.groupBy { groupUserScore -> groupUserScore.groupId }
.forEach { (groupId, scores) ->
val groupUserScores = scores.map { groupUserScore ->
val score = counts[groupUserScore.uid]?.count?.toInt() ?: 0

it.apply {
it.score = score
groupUserScore.apply {
groupUserScore.score = score
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class PoseSnapshotService(
}
}

suspend fun countByUidsAndCreatedAtBetween(
suspend fun countByUidsAndModifiedAtBetween(
uids: List<Long>,
fromCreatedAt: LocalDateTime,
toCreatedAt: LocalDateTime,
fromModifiedAt: LocalDateTime,
toModifiedAt: LocalDateTime,
): List<PoseTypeCountModel> {
return withContext(Dispatchers.IO) {
poseSnapshotRepository.countByUidAndCreatedAt(
poseSnapshotRepository.countByUidAndModifiedAt(
uids = uids,
fromCreatedAt = fromCreatedAt,
toCreatedAt = toCreatedAt,
fromModifiedAt = fromModifiedAt,
toModifiedAt = toModifiedAt,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ interface PoseSnapshotRepository : JpaRepository<PoseSnapshot, Long>, PoseSnapsh
interface PoseSnapshotQRepository {
fun countByUidsAndDate(uids: List<Long>, date: LocalDate): List<PoseTypeCountModel>

fun countByUidAndCreatedAt(
fun countByUidAndModifiedAt(
uids: List<Long>,
fromCreatedAt: LocalDateTime,
toCreatedAt: LocalDateTime,
fromModifiedAt: LocalDateTime,
toModifiedAt: LocalDateTime,
): List<PoseTypeCountModel>
}

Expand Down Expand Up @@ -60,10 +60,10 @@ class PoseSnapshotQRepositoryImpl : PoseSnapshotQRepository, QuerydslRepositoryS
.fetch()
}

override fun countByUidAndCreatedAt(
override fun countByUidAndModifiedAt(
uids: List<Long>,
fromCreatedAt: LocalDateTime,
toCreatedAt: LocalDateTime
fromModifiedAt: LocalDateTime,
toModifiedAt: LocalDateTime
): List<PoseTypeCountModel> {
return JPAQuery<QPoseSnapshot>(entityManager)
.select(
Expand All @@ -76,7 +76,7 @@ class PoseSnapshotQRepositoryImpl : PoseSnapshotQRepository, QuerydslRepositoryS
.from(qPoseSnapshot)
.where(
qPoseSnapshot.uid.`in`(uids),
qPoseSnapshot.createdAt.between(fromCreatedAt, toCreatedAt)
qPoseSnapshot.modifiedAt.between(fromModifiedAt, toModifiedAt)
)
.groupBy(qPoseSnapshot.uid, qPoseSnapshot.type)
.fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class PoseSnapshotListener(
val to = event.poseSnapshot.createdAt
val from = to.minusHours(1)

val score = poseSnapshotService.countByUidsAndCreatedAtBetween(
val score = poseSnapshotService.countByUidsAndModifiedAtBetween(
uids = listOf(event.poseSnapshot.uid),
fromCreatedAt = from,
toCreatedAt = to
fromModifiedAt = from,
toModifiedAt = to
).filter { model -> model.type in BAD_POSE }.sumOf { model -> model.count }.toInt()

val groupUserScore = groupUserScoreService.createOrUpdateGroupUserScore(this, score)
Expand Down

0 comments on commit 544c9ef

Please sign in to comment.