Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/#283] 아티클 개수가 10의 배수일 경우 마지막 스크롤에서 isLast=false로 응답되는 문제 해결 #284

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class ArticleViewCountDao(
.where(field("row_rank_tb.${ARTICLE_VIEW_COUNT.ARTICLE_ID.name}")!!.eq(query.articleId))
.query

fun selectArticlesOrderByViews(query: SelectArticlesOrderByViewsQuery): Set<SelectArticleViewsRecord> {
fun selectArticlesOrderByViews(query: SelectArticlesOrderByViewsQuery): List<SelectArticleViewsRecord> {
return selectArticlesOrderByViewsQuery(query)
.fetchInto(SelectArticleViewsRecord::class.java)
.toSet()
}

fun selectArticlesOrderByViewsQuery(query: SelectArticlesOrderByViewsQuery) = dslContext
Expand All @@ -88,6 +87,6 @@ class ArticleViewCountDao(
(null) -> noCondition()
else -> field("article_view_count_offset_tb.category_cd").eq(query.category.code)
}
).limit(10)
).limit(11)
Comment on lines -91 to +90
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조회수 상위 10개 아티클 ID를 조회할 때 10개가 아닌 11개로 일단 조회

.query
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ class ReadArticlesUseCase(
}

// 이번 스크롤에서 보여줄 아티클 ID에 대한 기준 (Criterion)
val articleViewsRecords: Set<SelectArticleViewsRecord> = articleViewCountDao.selectArticlesOrderByViews(
val articleViewsRecords: MutableList<SelectArticleViewsRecord> = articleViewCountDao.selectArticlesOrderByViews(
SelectArticlesOrderByViewsQuery(
offset,
CategoryType.fromCode(useCaseIn.categoryCd)
)
)
).toMutableList()

val isLast = if (articleViewsRecords.size == 11) {
articleViewsRecords.removeAt(10)
false
} else {
true
}
Comment on lines +45 to +50
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11개를 조회한 뒤, 그 개수가 11개일 경우에만 해당 스크롤의 isLast 필드를 false로 응답. 그렇지 않으면 true


// 2. TODO: 조회한 10개의 아티클 아이디를 기반으로 로컬 캐시에 있는지 조회(아티클 단건조회 캐시 사용)
// 3. TODO: 로컬캐시에 없으면 ARTICLE_MAIN_CARD 테이블에서 데이터가 있는지 조회 (컨텐츠는 article_ifo에서)
Expand Down Expand Up @@ -97,12 +104,12 @@ class ReadArticlesUseCase(
)
}.toList()

return ReadArticlesUseCaseOut(articleUseCaseOuts, sortedArticles.size != 10)
return ReadArticlesUseCaseOut(articleUseCaseOuts, isLast)
Comment on lines -100 to +107
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스크린샷 2024-08-03 오후 6 20 59

여기서 10보다 작다로 하면 되는거 아닌가요..?

}

private fun updateAndSortArticleViews(
articleRecords: Set<ArticleMainCardRecord>,
articleViewsRecords: Set<SelectArticleViewsRecord>,
articleViewsRecords: List<SelectArticleViewsRecord>,
): Set<ArticleMainCardRecord> {
val sortedSet = TreeSet(
Comparator<ArticleMainCardRecord> { a1, a2 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.few.data.common.code
* @see com.few.batch.data.common.code.BatchCategoryType
*/
enum class CategoryType(val code: Byte, val displayName: String) {
All(-1, "전체"), // Should not be stored in the DB
Comment on lines 6 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 PR과는 무관하지만 아티클 전체 카테고리 추가되었습니다

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

ECONOMY(0, "경제"),
IT(10, "IT"),
MARKETING(20, "마케팅"),
Expand Down
Loading