From cf185d6256ab5106e7e956ed91c329af49b842d3 Mon Sep 17 00:00:00 2001 From: Jihun-Hwang Date: Sat, 3 Aug 2024 16:43:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EC=95=84=ED=8B=B0=ED=81=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=88=98=20=EC=88=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=EC=8B=9C=20=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80(article?= =?UTF-8?q?=EC=B5=9C=EC=8B=A0=EC=88=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repo/dao/article/ArticleViewCountDao.kt | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt index 9aec5f988..62a377c19 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt @@ -7,8 +7,6 @@ import com.few.api.repo.dao.article.query.SelectRankByViewsQuery import com.few.api.repo.dao.article.record.SelectArticleViewsRecord import jooq.jooq_dsl.tables.ArticleViewCount.ARTICLE_VIEW_COUNT import org.jooq.DSLContext -import org.jooq.Record2 -import org.jooq.SelectLimitPercentStep import org.jooq.impl.DSL.* import org.springframework.stereotype.Repository @@ -56,13 +54,12 @@ class ArticleViewCountDao( fun selectRankByViewsQuery(query: SelectRankByViewsQuery) = dslContext .select(field("row_rank_tb.offset", Long::class.java)) .from( - dslContext - .select( - ARTICLE_VIEW_COUNT.ARTICLE_ID, - rowNumber().over(orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc())).`as`("offset") - ) - .from(ARTICLE_VIEW_COUNT) - .asTable("row_rank_tb") + dslContext.select( + ARTICLE_VIEW_COUNT.ARTICLE_ID, + rowNumber().over( + orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc(), ARTICLE_VIEW_COUNT.ARTICLE_ID.desc()) + ).`as`("offset") + ).from(ARTICLE_VIEW_COUNT).asTable("row_rank_tb") ) .where(field("row_rank_tb.${ARTICLE_VIEW_COUNT.ARTICLE_ID.name}")!!.eq(query.articleId)) .query @@ -73,26 +70,22 @@ class ArticleViewCountDao( .toSet() } - fun selectArticlesOrderByViewsQuery(query: SelectArticlesOrderByViewsQuery): SelectLimitPercentStep> { - val articleViewCountOffsetTb = select() - .from(ARTICLE_VIEW_COUNT) - .where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull) - .orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc()) - .limit(query.offset, Long.MAX_VALUE) - .asTable("article_view_count_offset_tb") - - val baseQuery = dslContext.select( + fun selectArticlesOrderByViewsQuery(query: SelectArticlesOrderByViewsQuery) = dslContext + .select( field("article_view_count_offset_tb.article_id").`as`(SelectArticleViewsRecord::articleId.name), field("article_view_count_offset_tb.view_count").`as`(SelectArticleViewsRecord::views.name) - ) - .from(articleViewCountOffsetTb) - - return if (query.category != null) { - baseQuery.where(field("article_view_count_offset_tb.category_cd").eq(query.category.code)) - .limit(10) - } else { - baseQuery - .limit(10) - } // TODO: .query로 리턴하면 리턴 타입이 달라져 못받는 문제 - } + ).from( + select() + .from(ARTICLE_VIEW_COUNT) + .where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull) + .orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc(), ARTICLE_VIEW_COUNT.ARTICLE_ID.desc()) + .limit(query.offset, Long.MAX_VALUE) + .asTable("article_view_count_offset_tb") + ).where( + when (query.category) { + (null) -> noCondition() + else -> field("article_view_count_offset_tb.category_cd").eq(query.category.code) + } + ).limit(10) + .query } \ No newline at end of file From ef55d395d83f414a6101dfe6b6e9e96561387633 Mon Sep 17 00:00:00 2001 From: Jihun-Hwang Date: Sat, 3 Aug 2024 16:50:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20ARTICLE=5FVIEW=5FCOUNT=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20DELETED=5FAT=20is=20null=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/few/api/repo/dao/article/ArticleViewCountDao.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt index 62a377c19..fa7eb1607 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt @@ -59,7 +59,9 @@ class ArticleViewCountDao( rowNumber().over( orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc(), ARTICLE_VIEW_COUNT.ARTICLE_ID.desc()) ).`as`("offset") - ).from(ARTICLE_VIEW_COUNT).asTable("row_rank_tb") + ).from(ARTICLE_VIEW_COUNT) + .where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull) + .asTable("row_rank_tb") ) .where(field("row_rank_tb.${ARTICLE_VIEW_COUNT.ARTICLE_ID.name}")!!.eq(query.articleId)) .query