test #69

Merged
klaus merged 2 commits from test into main 2023-11-07 08:21:57 +00:00
5 changed files with 55 additions and 116 deletions
Showing only changes of commit 9a394b7dae - Show all commits

View File

@ -55,8 +55,6 @@ dependencies {
implementation("org.json:json:20230227") implementation("org.json:json:20230227")
implementation("com.google.code.findbugs:jsr305:3.0.2") implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
// firebase admin sdk // firebase admin sdk
implementation("com.google.firebase:firebase-admin:9.2.0") implementation("com.google.firebase:firebase-admin:9.2.0")

View File

@ -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() }
}
}

View File

@ -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))
}
}

View File

@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController
class AudioContentMainController(private val service: AudioContentMainService) { class AudioContentMainController(private val service: AudioContentMainService) {
@GetMapping @GetMapping
suspend fun getMain( fun getMain(
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run { ) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.") if (member == null) throw SodaException("로그인 정보를 확인해주세요.")

View File

@ -1,8 +1,5 @@
package kr.co.vividnext.sodalive.content.main 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.AudioContentRepository
import kr.co.vividnext.sodalive.content.AudioContentService import kr.co.vividnext.sodalive.content.AudioContentService
import kr.co.vividnext.sodalive.content.main.banner.AudioContentBannerType import kr.co.vividnext.sodalive.content.main.banner.AudioContentBannerType
@ -29,100 +26,68 @@ class AudioContentMainService(
private val orderService: OrderService, private val orderService: OrderService,
private val audioContentThemeRepository: AudioContentThemeQueryRepository, private val audioContentThemeRepository: AudioContentThemeQueryRepository,
private val semaphoreManager: SemaphoreManager,
@Value("\${cloud.aws.cloud-front.host}") @Value("\${cloud.aws.cloud-front.host}")
private val imageHost: String private val imageHost: String
) { ) {
suspend fun getMain(memberId: Long, isAdult: Boolean): GetAudioContentMainResponse { fun getMain(memberId: Long, isAdult: Boolean): GetAudioContentMainResponse {
return coroutineScope { // 2주일 이내에 콘텐츠를 올린 크리에이터 20명 조회
// 2주일 이내에 콘텐츠를 올린 크리에이터 20명 조회 val newContentUploadCreatorList = getNewContentUploadCreatorList(memberId = memberId, isAdult = isAdult)
val newContentUploadCreatorList = async {
semaphoreManager.withPermit { val bannerList = getAudioContentMainBannerList(memberId = memberId, isAdult = isAdult)
getNewContentUploadCreatorList(memberId = memberId, isAdult = isAdult)
} // 구매목록 20개
val orderList = orderService.getAudioContentMainOrderList(
memberId = memberId,
limit = 20
)
// 콘텐츠 테마
val themeList = audioContentThemeRepository.getActiveThemeOfContent(isAdult = isAdult)
// 새 콘텐츠 20개 - 시간 내림차순 정렬
val newContentList = repository.findByTheme(
cloudfrontHost = imageHost,
isAdult = isAdult
)
.asSequence()
.filter {
!blockMemberRepository.isBlocked(
blockedMemberId = memberId,
memberId = it.creatorId
)
} }
.toList()
val bannerList = async { val curationList = getAudioContentCurationList(memberId = memberId, isAdult = isAdult)
semaphoreManager.withPermit {
getAudioContentMainBannerList(memberId = memberId, isAdult = isAdult)
}
}
// 구매목록 20개 val currentDateTime = LocalDateTime.now()
val orderList = async { val startDate = currentDateTime
semaphoreManager.withPermit { .minusWeeks(1)
orderService.getAudioContentMainOrderList( .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
memberId = memberId, .withHour(15)
limit = 20 .withMinute(0)
) .withSecond(0)
} val endDate = startDate.plusDays(7)
}
// 콘텐츠 테마 val contentRankingSortTypeList = audioContentService.getContentRankingSortTypeList()
val themeList = async { val contentRanking = audioContentService.getAudioContentRanking(
semaphoreManager.withPermit { isAdult = isAdult,
audioContentThemeRepository.getActiveThemeOfContent(isAdult = isAdult) startDate = startDate,
} endDate = endDate,
} offset = 0,
limit = 12
)
// 새 콘텐츠 20개 - 시간 내림차순 정렬 return GetAudioContentMainResponse(
val newContentList = async { newContentUploadCreatorList = newContentUploadCreatorList,
semaphoreManager.withPermit { bannerList = bannerList,
repository.findByTheme( orderList = orderList,
cloudfrontHost = imageHost, themeList = themeList,
isAdult = isAdult newContentList = newContentList,
) curationList = curationList,
.asSequence() contentRankingSortTypeList = contentRankingSortTypeList,
.filter { contentRanking = contentRanking
!blockMemberRepository.isBlocked( )
blockedMemberId = memberId,
memberId = it.creatorId
)
}
.toList()
}
}
val curationList = async {
semaphoreManager.withPermit {
getAudioContentCurationList(memberId = memberId, isAdult = isAdult)
}
}
val currentDateTime = LocalDateTime.now()
val startDate = currentDateTime
.minusWeeks(1)
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
.withHour(15)
.withMinute(0)
.withSecond(0)
val endDate = startDate.plusDays(7)
val contentRankingSortTypeList = audioContentService.getContentRankingSortTypeList()
val contentRanking = async {
semaphoreManager.withPermit {
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(),
contentRankingSortTypeList = contentRankingSortTypeList,
contentRanking = contentRanking.await()
)
}
} }
fun getThemeList(member: Member): List<String> { fun getThemeList(member: Member): List<String> {