HomeService fetchData 리팩토링 및 DB JOIN 기반 번역 적용
fetchData 함수에서 별도로 수행하던 번역 데이터 조회를 DB JOIN 및 COALESCE를 사용하도록 개선하여 성능을 최적화함. - AudioContentRepository, RankingRepository 등에 locale 파라미터 추가 - DB 레벨에서 번역된 제목을 조회하도록 쿼리 수정 - HomeService에서 불필요한 getTranslatedContentList 호출 제거
This commit is contained in:
@@ -69,7 +69,8 @@ class RankingRepository(
|
||||
offset: Long,
|
||||
limit: Long,
|
||||
sortType: String,
|
||||
theme: String = ""
|
||||
theme: String = "",
|
||||
locale: String? = null
|
||||
): List<GetAudioContentRankingItem> {
|
||||
val blockMemberCondition = if (memberId != null) {
|
||||
blockMember.member.id.eq(member.id)
|
||||
@@ -79,6 +80,8 @@ class RankingRepository(
|
||||
null
|
||||
}
|
||||
|
||||
val contentTranslation = kr.co.vividnext.sodalive.content.translation.QContentTranslation.contentTranslation
|
||||
|
||||
var where = audioContent.isActive.isTrue
|
||||
.and(audioContent.member.isActive.isTrue)
|
||||
.and(audioContent.member.isNotNull)
|
||||
@@ -109,11 +112,26 @@ class RankingRepository(
|
||||
where = where.and(audioContentTheme.theme.eq(theme))
|
||||
}
|
||||
|
||||
val titleExpression = if (locale != null) {
|
||||
val translatedTitle = Expressions.stringTemplate(
|
||||
"JSON_EXTRACT({0}, '$.title')",
|
||||
contentTranslation.renderedPayload
|
||||
)
|
||||
val coalesceTitle = Expressions.stringTemplate(
|
||||
"COALESCE(NULLIF({0}, ''), {1})",
|
||||
translatedTitle,
|
||||
audioContent.title
|
||||
)
|
||||
coalesceTitle
|
||||
} else {
|
||||
audioContent.title
|
||||
}
|
||||
|
||||
var select = queryFactory
|
||||
.select(
|
||||
QGetAudioContentRankingItem(
|
||||
audioContent.id,
|
||||
audioContent.title,
|
||||
titleExpression,
|
||||
audioContent.coverImage.prepend("/").prepend(imageHost),
|
||||
audioContentTheme.theme,
|
||||
audioContent.price,
|
||||
@@ -167,6 +185,11 @@ class RankingRepository(
|
||||
}
|
||||
}
|
||||
|
||||
if (locale != null) {
|
||||
select = select.leftJoin(contentTranslation)
|
||||
.on(contentTranslation.contentId.eq(audioContent.id).and(contentTranslation.locale.eq(locale)))
|
||||
}
|
||||
|
||||
if (memberId != null) {
|
||||
where = where.and(blockMember.id.isNull)
|
||||
select = select.leftJoin(blockMember).on(blockMemberCondition)
|
||||
|
||||
@@ -9,6 +9,7 @@ import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesPublishedDaysOfWeek
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesState
|
||||
import kr.co.vividnext.sodalive.explorer.GetExplorerSectionResponse
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.LocalDateTime
|
||||
@@ -17,6 +18,7 @@ import java.time.LocalDateTime
|
||||
class RankingService(
|
||||
private val repository: RankingRepository,
|
||||
private val seriesContentRepository: ContentSeriesContentRepository,
|
||||
private val langContext: LangContext,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
@@ -59,7 +61,8 @@ class RankingService(
|
||||
offset = offset,
|
||||
limit = limit,
|
||||
sortType = sortType,
|
||||
theme = theme
|
||||
theme = theme,
|
||||
locale = langContext.lang.code
|
||||
)
|
||||
loopCount++
|
||||
} while (contentList.size < 5 && loopCount < 5)
|
||||
|
||||
Reference in New Issue
Block a user