인기 캐릭터 번역 조회 개선
This commit is contained in:
@@ -100,7 +100,7 @@ class ChatCharacterController(
|
||||
}
|
||||
|
||||
// 인기 캐릭터 조회
|
||||
val popularCharacters = service.getPopularCharacters()
|
||||
val popularCharacters = service.getPopularCharacters(locale = langContext.lang.code)
|
||||
|
||||
// 최근 등록된 캐릭터 리스트 조회
|
||||
val newCharacters = service.getRecentCharactersPage(
|
||||
@@ -138,7 +138,7 @@ class ChatCharacterController(
|
||||
CharacterMainResponse(
|
||||
banners = banners,
|
||||
recentCharacters = translatedRecentCharacters,
|
||||
popularCharacters = getTranslatedAiCharacterList(popularCharacters),
|
||||
popularCharacters = popularCharacters,
|
||||
newCharacters = getTranslatedAiCharacterList(newCharacters),
|
||||
recommendCharacters = getTranslatedAiCharacterList(recommendCharacters),
|
||||
curationSections = curationSections
|
||||
|
||||
@@ -77,18 +77,23 @@ class ChatCharacterService(
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["popularCharacters_24h"],
|
||||
key = "T(kr.co.vividnext.sodalive.chat.character.service.RankingWindowCalculator).now('popular-character').cacheKey"
|
||||
cacheNames = ["popularCharacters_24h_locale"],
|
||||
key = "T(kr.co.vividnext.sodalive.chat.character.service.RankingWindowCalculator)" +
|
||||
".now('popular-character').cacheKey + '-' + #locale"
|
||||
)
|
||||
fun getPopularCharacters(limit: Long = 20): List<Character> {
|
||||
fun getPopularCharacters(locale: String, limit: Long = 20): List<Character> {
|
||||
val window = RankingWindowCalculator.now("popular-character")
|
||||
val topIds = popularCharacterQuery.findPopularCharacterIds(window.windowStart, window.nextBoundary, limit)
|
||||
val list = loadCharactersInOrder(topIds)
|
||||
val results = popularCharacterQuery.findPopularCharactersWithTranslation(
|
||||
window.windowStart,
|
||||
window.nextBoundary,
|
||||
limit,
|
||||
locale
|
||||
)
|
||||
|
||||
val recentSet = if (list.isNotEmpty()) {
|
||||
val recentSet = if (results.isNotEmpty()) {
|
||||
imageRepository
|
||||
.findCharacterIdsWithRecentImages(
|
||||
list.map { it.id!! },
|
||||
results.map { it.id },
|
||||
LocalDateTime.now().minusDays(3)
|
||||
)
|
||||
.toSet()
|
||||
@@ -96,11 +101,11 @@ class ChatCharacterService(
|
||||
emptySet()
|
||||
}
|
||||
|
||||
return list.map {
|
||||
return results.map {
|
||||
Character(
|
||||
characterId = it.id!!,
|
||||
name = it.name,
|
||||
description = it.description,
|
||||
characterId = it.id,
|
||||
name = it.translatedPayload?.name.takeIf { name -> !name.isNullOrBlank() } ?: it.name,
|
||||
description = it.translatedPayload?.description.takeIf { desc -> !desc.isNullOrBlank() } ?: it.description,
|
||||
imageUrl = "$imageHost/${it.imagePath ?: "profile/default-profile.png"}",
|
||||
new = recentSet.contains(it.id)
|
||||
)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package kr.co.vividnext.sodalive.chat.character.service
|
||||
|
||||
import com.querydsl.core.types.Projections
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.chat.character.QChatCharacter
|
||||
import kr.co.vividnext.sodalive.chat.character.translate.AiCharacterTranslationRenderedPayload
|
||||
import kr.co.vividnext.sodalive.chat.character.translate.QAiCharacterTranslation
|
||||
import kr.co.vividnext.sodalive.chat.room.ParticipantType
|
||||
import kr.co.vividnext.sodalive.chat.room.QChatMessage
|
||||
import kr.co.vividnext.sodalive.chat.room.QChatParticipant
|
||||
@@ -51,4 +54,56 @@ class PopularCharacterQuery(
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
data class PopularCharacterQueryResult(
|
||||
val id: Long,
|
||||
val name: String,
|
||||
val description: String,
|
||||
val imagePath: String?,
|
||||
val translatedPayload: AiCharacterTranslationRenderedPayload?
|
||||
)
|
||||
|
||||
fun findPopularCharactersWithTranslation(
|
||||
windowStart: Instant,
|
||||
endExclusive: Instant,
|
||||
limit: Long,
|
||||
locale: String
|
||||
): List<PopularCharacterQueryResult> {
|
||||
val m = QChatMessage.chatMessage
|
||||
val p = QChatParticipant.chatParticipant
|
||||
val c = QChatCharacter.chatCharacter
|
||||
val t = QAiCharacterTranslation.aiCharacterTranslation
|
||||
|
||||
val start = LocalDateTime.ofInstant(windowStart, ZoneOffset.UTC)
|
||||
val end = LocalDateTime.ofInstant(endExclusive, ZoneOffset.UTC)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
PopularCharacterQueryResult::class.java,
|
||||
c.id,
|
||||
c.name,
|
||||
c.description,
|
||||
c.imagePath,
|
||||
t.renderedPayload
|
||||
)
|
||||
)
|
||||
.from(m)
|
||||
.join(p).on(
|
||||
p.chatRoom.id.eq(m.chatRoom.id)
|
||||
.and(p.participantType.eq(ParticipantType.CHARACTER))
|
||||
)
|
||||
.join(c).on(c.id.eq(p.character.id))
|
||||
.leftJoin(t).on(t.characterId.eq(c.id).and(t.locale.eq(locale)))
|
||||
.where(
|
||||
m.createdAt.goe(start)
|
||||
.and(m.createdAt.lt(end))
|
||||
.and(m.isActive.isTrue)
|
||||
.and(c.isActive.isTrue)
|
||||
)
|
||||
.groupBy(c.id, c.name, c.description, c.imagePath, t.id, t.renderedPayload)
|
||||
.orderBy(m.id.count().desc())
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user