fix(popular): 일일 인기 캐릭터 집계 윈도우를 전날 완료 구간으로 고정
- UTC 20:00 경계 직후에도 [전날 20:00, 당일 20:00) 범위 사용으로 일일 순위 정확화 - RankingWindowCalculator.now(): lastBoundary 기반 [start, endExclusive) 계산
This commit is contained in:
parent
dd0a1c2293
commit
4adc3e127c
|
@ -23,16 +23,24 @@ object RankingWindowCalculator {
|
|||
fun now(prefix: String = "popular-chat-character"): RankingWindow {
|
||||
val now = ZonedDateTime.now(ZONE)
|
||||
val todayBoundary = now.toLocalDate().atTime(BOUNDARY_HOUR, 0, 0).atZone(ZONE)
|
||||
val (start, endExclusive, nextBoundary) = if (now.isBefore(todayBoundary)) {
|
||||
val start = todayBoundary.minusDays(1)
|
||||
Triple(start, todayBoundary, todayBoundary)
|
||||
|
||||
// 일일 순위는 "전날" 완료 구간을 보여주기 위해, 언제든 직전 경계까지만 집계한다.
|
||||
// 예) 2025-09-14 20:00:00 직후에도 [2025-09-13 20:00, 2025-09-14 20:00) 윈도우를 사용
|
||||
val lastBoundary = if (now.isBefore(todayBoundary)) {
|
||||
// 아직 오늘 20:00 이전이면, 직전 경계는 어제 20:00
|
||||
todayBoundary.minusDays(1)
|
||||
} else {
|
||||
val next = todayBoundary.plusDays(1)
|
||||
Triple(todayBoundary, next, next)
|
||||
// 오늘 20:00을 지났거나 같으면, 직전 경계는 오늘 20:00
|
||||
todayBoundary
|
||||
}
|
||||
|
||||
val start = lastBoundary.minusDays(1)
|
||||
val endExclusive = lastBoundary
|
||||
|
||||
val windowStart = start.toInstant()
|
||||
val windowEnd = endExclusive.minusNanos(1).toInstant() // [start, end]
|
||||
val windowEnd = endExclusive.minusSeconds(1).toInstant() // [start, end]
|
||||
val cacheKey = "$prefix:${windowStart.epochSecond}"
|
||||
return RankingWindow(windowStart, windowEnd, nextBoundary.toInstant(), cacheKey)
|
||||
// nextBoundary 필드는 기존 시그니처 유지를 위해 endExclusive(=lastBoundary)를 그대로 전달한다.
|
||||
return RankingWindow(windowStart, windowEnd, endExclusive.toInstant(), cacheKey)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue