feat(home): 응원 크리에이터 집계 쿼리를 변경한다

This commit is contained in:
2026-07-10 06:05:37 +09:00
parent c9e35f2ed4
commit 4f348c3643
4 changed files with 78 additions and 40 deletions

View File

@@ -12,7 +12,7 @@ import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
@Entity
data class UseCanCalculate(
class UseCanCalculate(
val can: Int,
@Column(nullable = false)

View File

@@ -570,9 +570,10 @@ class DefaultHomeRecommendationQueryRepository(
override fun findCheerCreatorSnapshots(
windowStart: LocalDateTime,
snapshotAt: LocalDateTime,
windowEndExclusive: LocalDateTime,
limit: Int
): List<RecommendationSnapshotRecord> {
val snapshotAt = windowEndExclusive.minusSeconds(1)
val sql = """
with creator_debut as (
select debut_events.creator_id as creator_id, min(debut_events.debut_at) as debut_at
@@ -595,14 +596,14 @@ class DefaultHomeRecommendationQueryRepository(
donation_stats as (
select ucc.recipient_creator_id as creator_id,
coalesce(sum(ucc.can), 0) as donation_amount,
count(ucc.id) as donation_count
count(distinct ucc.use_can_id) as donation_count
from use_can_calculate ucc
join use_can uc on uc.id = ucc.use_can_id
where ucc.status = 'RECEIVED'
and uc.is_refund = false
and uc.can_usage = 'CHANNEL_DONATION'
and ucc.created_at >= :windowStart
and ucc.created_at <= :snapshotAt
and ucc.created_at < :windowEndExclusive
group by ucc.recipient_creator_id
),
fan_talk_stats as (
@@ -610,17 +611,17 @@ class DefaultHomeRecommendationQueryRepository(
from creator_cheers ch
where ch.is_active = true
and ch.created_at >= :windowStart
and ch.created_at <= :snapshotAt
and ch.created_at < :windowEndExclusive
group by ch.creator_id
)
select m.id as target_id,
((coalesce(ds.donation_amount, 0) * ${RecommendationScoreSpec.CHEER_DONATION_AMOUNT_WEIGHT} +
coalesce(fts.fan_talk_count, 0) * ${RecommendationScoreSpec.CHEER_FAN_TALK_WEIGHT} +
coalesce(ds.donation_count, 0) * ${RecommendationScoreSpec.CHEER_DONATION_COUNT_WEIGHT}) *
case
when cd.debut_at >= :boost10Start then ${RecommendationScoreSpec.NEW_BOOST_10_DAYS}
when cd.debut_at >= :boost20Start then ${RecommendationScoreSpec.NEW_BOOST_20_DAYS}
when cd.debut_at >= :boost30Start then ${RecommendationScoreSpec.NEW_BOOST_30_DAYS}
coalesce(ds.donation_count, 0) * ${RecommendationScoreSpec.CHEER_DONATION_COUNT_WEIGHT}) *
case
when cd.debut_at >= :boost10Start then ${RecommendationScoreSpec.CHEER_NEW_BOOST_10_DAYS}
when cd.debut_at >= :boost20Start then ${RecommendationScoreSpec.CHEER_NEW_BOOST_20_DAYS}
when cd.debut_at >= :boost30Start then ${RecommendationScoreSpec.CHEER_NEW_BOOST_30_DAYS}
else ${RecommendationScoreSpec.DEFAULT_NEW_BOOST}
end) as score,
rand() as random_tie_breaker
@@ -635,7 +636,14 @@ class DefaultHomeRecommendationQueryRepository(
limit :limit
""".trimIndent()
return executeSnapshotQuery(sql, RecommendedSectionType.CHEER_CREATOR, windowStart, snapshotAt, limit)
return executeSnapshotQuery(
sql,
RecommendedSectionType.CHEER_CREATOR,
windowStart,
snapshotAt,
limit,
windowEndExclusive
)
}
override fun findPopularCommunitySnapshots(

View File

@@ -46,7 +46,7 @@ interface HomeRecommendationQueryPort {
fun findCheerCreatorSnapshots(
windowStart: LocalDateTime,
snapshotAt: LocalDateTime,
windowEndExclusive: LocalDateTime,
limit: Int
): List<RecommendationSnapshotRecord>