test #69
|
@ -55,8 +55,6 @@ dependencies {
|
|||
implementation("org.json:json:20230227")
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
|
||||
|
||||
// firebase admin sdk
|
||||
implementation("com.google.firebase:firebase-admin:9.2.0")
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
|
||||
class SemaphoreManager(private val semaphore: Semaphore) {
|
||||
suspend fun <T> withPermit(block: suspend () -> T): T {
|
||||
return semaphore.withPermit { block() }
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package kr.co.vividnext.sodalive.configs
|
||||
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kr.co.vividnext.sodalive.common.SemaphoreManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
@Configuration
|
||||
class SemaphoreConfig {
|
||||
@Bean
|
||||
fun semaphoreManager(): SemaphoreManager {
|
||||
return SemaphoreManager(Semaphore(4))
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController
|
|||
class AudioContentMainController(private val service: AudioContentMainService) {
|
||||
|
||||
@GetMapping
|
||||
suspend fun getMain(
|
||||
fun getMain(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package kr.co.vividnext.sodalive.content.main
|
||||
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kr.co.vividnext.sodalive.common.SemaphoreManager
|
||||
import kr.co.vividnext.sodalive.content.AudioContentRepository
|
||||
import kr.co.vividnext.sodalive.content.AudioContentService
|
||||
import kr.co.vividnext.sodalive.content.main.banner.AudioContentBannerType
|
||||
|
@ -29,47 +26,26 @@ class AudioContentMainService(
|
|||
private val orderService: OrderService,
|
||||
private val audioContentThemeRepository: AudioContentThemeQueryRepository,
|
||||
|
||||
private val semaphoreManager: SemaphoreManager,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
) {
|
||||
suspend fun getMain(memberId: Long, isAdult: Boolean): GetAudioContentMainResponse {
|
||||
return coroutineScope {
|
||||
fun getMain(memberId: Long, isAdult: Boolean): GetAudioContentMainResponse {
|
||||
// 2주일 이내에 콘텐츠를 올린 크리에이터 20명 조회
|
||||
val newContentUploadCreatorList = async {
|
||||
semaphoreManager.withPermit {
|
||||
getNewContentUploadCreatorList(memberId = memberId, isAdult = isAdult)
|
||||
}
|
||||
}
|
||||
val newContentUploadCreatorList = getNewContentUploadCreatorList(memberId = memberId, isAdult = isAdult)
|
||||
|
||||
val bannerList = async {
|
||||
semaphoreManager.withPermit {
|
||||
getAudioContentMainBannerList(memberId = memberId, isAdult = isAdult)
|
||||
}
|
||||
}
|
||||
val bannerList = getAudioContentMainBannerList(memberId = memberId, isAdult = isAdult)
|
||||
|
||||
// 구매목록 20개
|
||||
val orderList = async {
|
||||
semaphoreManager.withPermit {
|
||||
orderService.getAudioContentMainOrderList(
|
||||
val orderList = orderService.getAudioContentMainOrderList(
|
||||
memberId = memberId,
|
||||
limit = 20
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 콘텐츠 테마
|
||||
val themeList = async {
|
||||
semaphoreManager.withPermit {
|
||||
audioContentThemeRepository.getActiveThemeOfContent(isAdult = isAdult)
|
||||
}
|
||||
}
|
||||
val themeList = audioContentThemeRepository.getActiveThemeOfContent(isAdult = isAdult)
|
||||
|
||||
// 새 콘텐츠 20개 - 시간 내림차순 정렬
|
||||
val newContentList = async {
|
||||
semaphoreManager.withPermit {
|
||||
repository.findByTheme(
|
||||
val newContentList = repository.findByTheme(
|
||||
cloudfrontHost = imageHost,
|
||||
isAdult = isAdult
|
||||
)
|
||||
|
@ -81,14 +57,8 @@ class AudioContentMainService(
|
|||
)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
|
||||
val curationList = async {
|
||||
semaphoreManager.withPermit {
|
||||
getAudioContentCurationList(memberId = memberId, isAdult = isAdult)
|
||||
}
|
||||
}
|
||||
val curationList = getAudioContentCurationList(memberId = memberId, isAdult = isAdult)
|
||||
|
||||
val currentDateTime = LocalDateTime.now()
|
||||
val startDate = currentDateTime
|
||||
|
@ -100,30 +70,25 @@ class AudioContentMainService(
|
|||
val endDate = startDate.plusDays(7)
|
||||
|
||||
val contentRankingSortTypeList = audioContentService.getContentRankingSortTypeList()
|
||||
val contentRanking = async {
|
||||
semaphoreManager.withPermit {
|
||||
audioContentService.getAudioContentRanking(
|
||||
val contentRanking = audioContentService.getAudioContentRanking(
|
||||
isAdult = isAdult,
|
||||
startDate = startDate,
|
||||
endDate = endDate,
|
||||
offset = 0,
|
||||
limit = 12
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
GetAudioContentMainResponse(
|
||||
newContentUploadCreatorList = newContentUploadCreatorList.await(),
|
||||
bannerList = bannerList.await(),
|
||||
orderList = orderList.await(),
|
||||
themeList = themeList.await(),
|
||||
newContentList = newContentList.await(),
|
||||
curationList = curationList.await(),
|
||||
return GetAudioContentMainResponse(
|
||||
newContentUploadCreatorList = newContentUploadCreatorList,
|
||||
bannerList = bannerList,
|
||||
orderList = orderList,
|
||||
themeList = themeList,
|
||||
newContentList = newContentList,
|
||||
curationList = curationList,
|
||||
contentRankingSortTypeList = contentRankingSortTypeList,
|
||||
contentRanking = contentRanking.await()
|
||||
contentRanking = contentRanking
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getThemeList(member: Member): List<String> {
|
||||
return audioContentThemeRepository.getActiveThemeOfContent(isAdult = member.auth != null)
|
||||
|
|
Loading…
Reference in New Issue