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/#281] 아티클 조회수 순 정렬시 옵션 추가(article최신순) #282

Merged
merged 2 commits into from
Aug 3, 2024

Conversation

hun-ca
Copy link
Member

@hun-ca hun-ca commented Aug 3, 2024

🎫 연관 이슈

resolved #281

💁‍♂️ PR 내용

  • DB에서 아티클 조회수 순 10개씩 조회 시, 아티클 최신순 옵션이 빠져있어 발생한 문제
    • DB에선 아티클 조회수 순 10개를 뽑아온 뒤, 그 10개를 애플리케이션에서 조회수가 같은 경우 최신순으로 정렬하고 있었음
    • 결국 디비 단에선 조회수가 같을 경우 아티클 최신순 조건이 발생되지 않음

🙏 작업

🙈 PR 참고 사항

📸 스크린샷

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@hun-ca hun-ca self-assigned this Aug 3, 2024
@github-actions github-actions bot added the fix 기능을 고칠 때 사용됩니다 label Aug 3, 2024
Copy link
Member Author

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

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

확인 부탁드립니다

Comment on lines -59 to +63
dslContext
.select(
ARTICLE_VIEW_COUNT.ARTICLE_ID,
rowNumber().over(orderBy(ARTICLE_VIEW_COUNT.VIEW_COUNT.desc())).`as`("offset")
)
.from(ARTICLE_VIEW_COUNT)
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)
.where(ARTICLE_VIEW_COUNT.DELETED_AT.isNull)
Copy link
Member Author

Choose a reason for hiding this comment

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

  • as-is: VIEW_COUNT 로만 내림 차순 하여 10개 가져옴
  • to-be: VIEW_COUNT가 같은 경우 ARTICLE_ID를 내림 차순하는 조건 추가(최신 글 우선)

Copy link
Member Author

Choose a reason for hiding this comment

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

CREATE TABLE ARTICLE_VIEW_COUNT
(
    article_id  BIGINT  NOT NULL,
    view_count  BIGINT  NOT NULL,
    category_cd TINYINT NOT NULL,
    deleted_at  TIMESTAMP NULL DEFAULT NULL,
    CONSTRAINT article_view_count_pk PRIMARY KEY (article_id)
);

위와 같이 article_id에 인덱싱이 되어 있어 인덱스 타고 갑니다

Comment on lines +86 to +91
).where(
when (query.category) {
(null) -> noCondition()
else -> field("article_view_count_offset_tb.category_cd").eq(query.category.code)
}
).limit(10)
Copy link
Member Author

Choose a reason for hiding this comment

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

카테고리 옵션이 추가로 온 경우에 대해 동적 쿼리 적용했습니다

@hun-ca hun-ca requested a review from belljun3395 August 3, 2024 07:52
@belljun3395
Copy link
Collaborator

네 확인했슴다.!

@hun-ca hun-ca merged commit bf06924 into main Aug 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 기능을 고칠 때 사용됩니다
Projects
None yet
Development

Successfully merging this pull request may close these issues.

아티클 목록 조회 시 최신 아티클이 우선순위 갖도록 버그 수정
2 participants