Skip to content

Commit

Permalink
test: stream 제거, 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jan 15, 2025
1 parent bd24ba4 commit 05dcb45
Showing 1 changed file with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,20 @@ class BrowseArticlesUseCase(
fun execute(useCaseIn: ReadArticlesUseCaseIn): ReadArticlesUseCaseOut {
val articleViewsRecords = articleViewRecordsService.execute(useCaseIn.prevArticleId, useCaseIn.categoryCd)

val isLast =
when (articleViewsRecords.size) {
11 -> {
articleViewsRecords.removeAt(10)
false
}
10 -> {
false
}
else -> {
true
}
}
val isLast = articleViewsRecords.size <= 10
val limitedArticleViewsRecords = articleViewsRecords.take(10)

val articleIds = articleViewsRecords.map { it.articleId }
val articleMainCardRecords: List<ArticleMainCardRecord> = articleMainCardDao.selectArticleMainCardsRecord(articleIds.toSet())
val selectArticleContentsRecords: List<SelectArticleContentsRecord> = articleDao.selectArticleContents(articleIds.toSet())
val articleIds = limitedArticleViewsRecords.map { it.articleId }.toSet()
val articleMainCardRecords: List<ArticleMainCardRecord> = articleMainCardDao.selectArticleMainCardsRecord(articleIds)
val selectArticleContentsRecords: List<SelectArticleContentsRecord> = articleDao.selectArticleContents(articleIds)

articleMainCardRecords.withIndex().forEach { (index, articleMainCardRecord) ->
articleMainCardRecord.content = selectArticleContentsRecords[index].content
val contentsMap = selectArticleContentsRecords.associateBy { it.articleId }
articleMainCardRecords.forEach { record ->
record.content = contentsMap[record.articleId]?.content ?: ""
}

val articleUseCaseOuts: List<ReadArticleUseCaseOut> =
articleMainCardRecords
.stream()
.map { a ->
ReadArticleUseCaseOut(
id = a.articleId,
Expand All @@ -65,8 +54,7 @@ class BrowseArticlesUseCase(
views = a.views,
workbooks =
a.workbooks
.stream()
.map { WorkbookDetail(it.id!!, it.title!!) }.toList()
.map { WorkbookDetail(it.id!!, it.title!!) }
)
}.toList()

Expand Down

0 comments on commit 05dcb45

Please sign in to comment.