feat(home): 응원 크리에이터 집계 쿼리를 변경한다
This commit is contained in:
@@ -12,7 +12,7 @@ import javax.persistence.JoinColumn
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
@Entity
|
||||
data class UseCanCalculate(
|
||||
class UseCanCalculate(
|
||||
val can: Int,
|
||||
|
||||
@Column(nullable = false)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -46,7 +46,7 @@ interface HomeRecommendationQueryPort {
|
||||
|
||||
fun findCheerCreatorSnapshots(
|
||||
windowStart: LocalDateTime,
|
||||
snapshotAt: LocalDateTime,
|
||||
windowEndExclusive: LocalDateTime,
|
||||
limit: Int
|
||||
): List<RecommendationSnapshotRecord>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user