Skip to content

Commit

Permalink
Merge branch 'dev' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
gouyeonch committed Sep 12, 2024
2 parents cfe6ce6 + 2f72ab5 commit 529f3af
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,17 @@ Page<News> 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<News> findByPopularityLessThan(
@Param("viewWeight") double viewWeight,
Expand All @@ -142,18 +141,15 @@ Page<News> 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<News> findFirstPageByPopularity(
@Param("viewWeight") double viewWeight,
Expand All @@ -167,6 +163,7 @@ Page<News> findFirstPageByPopularity(




/****************** 뉴스 검색 *************************/
// 최신순 검색
@Query("""
Expand Down

0 comments on commit 529f3af

Please sign in to comment.