From 2f72ab565eebe9e4da02570ec14d6d0da996431b Mon Sep 17 00:00:00 2001 From: Gouyeon Chung Date: Fri, 13 Sep 2024 02:37:01 +0900 Subject: [PATCH] =?UTF-8?q?FIX=20:=20=EC=9D=B8=EA=B8=B0=EC=88=9C=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=20=EC=A1=B0=ED=9A=8C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=ED=8B=B0=EB=B8=8C=20=EC=BF=BC=EB=A6=AC=20=EB=AC=B8=EB=B2=95=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B05?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../news/repository/NewsRepository.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/kkokkomu/short_news/news/repository/NewsRepository.java b/src/main/java/com/kkokkomu/short_news/news/repository/NewsRepository.java index 7e593d2..c6d24e4 100644 --- a/src/main/java/com/kkokkomu/short_news/news/repository/NewsRepository.java +++ b/src/main/java/com/kkokkomu/short_news/news/repository/NewsRepository.java @@ -118,18 +118,17 @@ Page findFirstPageByCategoryOrderByIdDesc( // 인기순 필터 쿼리 @Query(value = """ -SELECT n.id, n.shortform_url, n.youtube_url, n.instagram_url, n.thumbnail, - n.view_cnt, n.title, n.summary, n.shared_cnt, n.category, - n.created_at, n.edited_at, n.related_url, - (n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + - n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) AS popularityScore +SELECT n.* FROM news n LEFT JOIN comment c ON n.id = c.news_id LEFT JOIN news_reaction r ON n.id = r.news_id GROUP BY n.id -HAVING popularityScore < :cursorScore - OR (popularityScore = :cursorScore AND n.id < :cursorId) -ORDER BY popularityScore DESC, n.id DESC +HAVING (n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + + n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) < :cursorScore + OR ((n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + + n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) = :cursorScore AND n.id < :cursorId) +ORDER BY (n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + + n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) DESC, n.id DESC """, nativeQuery = true) Page findByPopularityLessThan( @Param("viewWeight") double viewWeight, @@ -142,18 +141,15 @@ Page findByPopularityLessThan( Pageable pageable ); - // 초기 페이지 인기순 필터 쿼리 + // 첫 페이지 인기순 필터 쿼리 @Query(value = """ -SELECT n.id, n.shortform_url, n.youtube_url, n.instagram_url, n.thumbnail, - n.view_cnt, n.title, n.summary, n.shared_cnt, n.category, - n.created_at, n.edited_at, n.related_url, - (n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + - n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) AS popularityScore +SELECT n.* FROM news n LEFT JOIN comment c ON n.id = c.news_id LEFT JOIN news_reaction r ON n.id = r.news_id GROUP BY n.id -ORDER BY popularityScore DESC, n.id DESC +ORDER BY (n.view_cnt * :viewWeight + COUNT(c.id) * :commentWeight + COUNT(r.id) * :reactionWeight + + n.shared_cnt * :shareWeight + TIMESTAMPDIFF(DAY, n.created_at, CURRENT_TIMESTAMP) * :dateWeight) DESC, n.id DESC """, nativeQuery = true) Page findFirstPageByPopularity( @Param("viewWeight") double viewWeight, @@ -167,6 +163,7 @@ Page findFirstPageByPopularity( + /****************** 뉴스 검색 *************************/ // 최신순 검색 @Query("""