feat(i18n): 번역 작업 큐와 언어 감지 캐시를 도입한다
조회 중 외부 번역 호출을 줄이고 누락 번역을 비동기 job으로 처리한다.
This commit is contained in:
@@ -60,6 +60,7 @@ class LanguageDetectListener(
|
||||
private val seriesRepository: ContentSeriesRepository,
|
||||
private val originalWorkRepository: OriginalWorkRepository,
|
||||
private val categoryRepository: CategoryRepository,
|
||||
private val languageDetectionCacheService: LanguageDetectionCacheService,
|
||||
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
|
||||
@@ -116,7 +117,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, characterId) ?: return
|
||||
val langCode = detectLanguageCode(event, characterId) ?: return
|
||||
|
||||
character.languageCode = langCode
|
||||
chatCharacterRepository.save(character)
|
||||
@@ -154,7 +155,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, contentId) ?: return
|
||||
val langCode = detectLanguageCode(event, contentId) ?: return
|
||||
|
||||
audioContent.languageCode = langCode
|
||||
|
||||
@@ -194,7 +195,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, commentId) ?: return
|
||||
val langCode = detectLanguageCode(event, commentId) ?: return
|
||||
|
||||
comment.languageCode = langCode
|
||||
audioContentCommentRepository.save(comment)
|
||||
@@ -226,7 +227,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, commentId) ?: return
|
||||
val langCode = detectLanguageCode(event, commentId) ?: return
|
||||
|
||||
comment.languageCode = langCode
|
||||
characterCommentRepository.save(comment)
|
||||
@@ -257,7 +258,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, cheersId) ?: return
|
||||
val langCode = detectLanguageCode(event, cheersId) ?: return
|
||||
|
||||
cheers.languageCode = langCode
|
||||
creatorCheersRepository.save(cheers)
|
||||
@@ -288,7 +289,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, seriesId) ?: return
|
||||
val langCode = detectLanguageCode(event, seriesId) ?: return
|
||||
|
||||
series.languageCode = langCode
|
||||
seriesRepository.save(series)
|
||||
@@ -326,7 +327,7 @@ class LanguageDetectListener(
|
||||
return
|
||||
}
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, originalWorkId) ?: return
|
||||
val langCode = detectLanguageCode(event, originalWorkId) ?: return
|
||||
|
||||
originalWork.languageCode = langCode
|
||||
originalWorkRepository.save(originalWork)
|
||||
@@ -352,7 +353,7 @@ class LanguageDetectListener(
|
||||
val category = categoryRepository.findByIdOrNull(categoryId) ?: return
|
||||
if (!category.languageCode.isNullOrBlank()) return
|
||||
|
||||
val langCode = requestPapagoLanguageCode(event.query, categoryId) ?: return
|
||||
val langCode = detectLanguageCode(event, categoryId) ?: return
|
||||
|
||||
category.languageCode = langCode
|
||||
categoryRepository.save(category)
|
||||
@@ -365,6 +366,12 @@ class LanguageDetectListener(
|
||||
)
|
||||
}
|
||||
|
||||
private fun detectLanguageCode(event: LanguageDetectEvent, targetIdForLog: Long): String? {
|
||||
return languageDetectionCacheService.detectWithCache(event.query) {
|
||||
requestPapagoLanguageCode(event.query, targetIdForLog)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestPapagoLanguageCode(query: String, targetIdForLog: Long): String? {
|
||||
return try {
|
||||
val headers = HttpHeaders().apply {
|
||||
|
||||
Reference in New Issue
Block a user