feat(home): AI 캐릭터 빈 스냅샷 마커를 저장한다
This commit is contained in:
@@ -18,11 +18,21 @@ class RecommendationSnapshotPersistenceAdapter(
|
||||
return repository.findLatestSnapshots(sectionType.name, offset, limit).map { it.toRecord() }
|
||||
}
|
||||
|
||||
override fun existsLatestSnapshot(sectionType: RecommendedSectionType): Boolean {
|
||||
return repository.existsBySectionType(sectionType)
|
||||
}
|
||||
|
||||
override fun replaceSnapshots(
|
||||
sectionType: RecommendedSectionType,
|
||||
snapshotAt: LocalDateTime,
|
||||
newSnapshots: List<RecommendationSnapshotRecord>
|
||||
) {
|
||||
if (newSnapshots.isEmpty() && sectionType == RecommendedSectionType.AI_CHARACTER) {
|
||||
repository.deleteBySectionType(sectionType)
|
||||
repository.save(emptySnapshotMarker(sectionType, snapshotAt).toEntity())
|
||||
return
|
||||
}
|
||||
|
||||
repository.deleteBySectionTypeAndSnapshotAt(sectionType, snapshotAt)
|
||||
repository.saveAll(newSnapshots.map { it.toEntity() })
|
||||
}
|
||||
@@ -46,4 +56,21 @@ class RecommendationSnapshotPersistenceAdapter(
|
||||
randomTieBreaker = randomTieBreaker
|
||||
)
|
||||
}
|
||||
|
||||
private fun emptySnapshotMarker(
|
||||
sectionType: RecommendedSectionType,
|
||||
snapshotAt: LocalDateTime
|
||||
): RecommendationSnapshotRecord {
|
||||
return RecommendationSnapshotRecord(
|
||||
sectionType = sectionType,
|
||||
targetId = EMPTY_SNAPSHOT_MARKER_TARGET_ID,
|
||||
score = 0.0,
|
||||
snapshotAt = snapshotAt,
|
||||
randomTieBreaker = 0.0
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EMPTY_SNAPSHOT_MARKER_TARGET_ID = 0L
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ interface RecommendationSnapshotRepository : JpaRepository<RecommendationSnapsho
|
||||
from recommendation_snapshot latest
|
||||
where latest.section_type = :sectionType
|
||||
)
|
||||
and rs.target_id <> 0
|
||||
order by rs.score desc, rs.random_tie_breaker asc
|
||||
limit :limit offset :offset
|
||||
""",
|
||||
@@ -29,4 +30,8 @@ interface RecommendationSnapshotRepository : JpaRepository<RecommendationSnapsho
|
||||
): List<RecommendationSnapshot>
|
||||
|
||||
fun deleteBySectionTypeAndSnapshotAt(sectionType: RecommendedSectionType, snapshotAt: LocalDateTime)
|
||||
|
||||
fun deleteBySectionType(sectionType: RecommendedSectionType)
|
||||
|
||||
fun existsBySectionType(sectionType: RecommendedSectionType): Boolean
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ interface RecommendationSnapshotPort {
|
||||
limit: Int = Int.MAX_VALUE
|
||||
): List<RecommendationSnapshotRecord>
|
||||
|
||||
fun existsLatestSnapshot(sectionType: RecommendedSectionType): Boolean
|
||||
|
||||
fun replaceSnapshots(
|
||||
sectionType: RecommendedSectionType,
|
||||
snapshotAt: LocalDateTime,
|
||||
|
||||
Reference in New Issue
Block a user