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

[REFACTOR] Notification 조회 N+1 문제 해결 #207

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

jaewonLeeKOR
Copy link
Member

PR 타입(하나 이상의 PR 타입을 선택해주세요)

  • 기능 추가
  • 기능 삭제
  • 버그 수정
  • 의존성, 환경 변수, 빌드 관련 코드 업데이트

반영 브랜치

refactor/#206/notificationN+1 -> develop

변경 사항

  • Notification 조회 N+1 문제 해결
    • @EntityGraph 어노테이션을 이용하여 fetch join을 구현했습니다.

테스트 결과

기존의 쿼리

select
    n1_0.id,
    n1_0.created_at,
    n1_0.deleted_at,
    n1_0.member_id,
    n1_0.notification_log_id,
    n1_0.type,
    n1_0.updated_at 
from
    notification n1_0 
where
    n1_0.id<=? 
    and (
        n1_0.member_id=? 
        or n1_0.type=4 
        or n1_0.type=5
    ) 
order by
    n1_0.created_at desc 
offset
    ? rows 
fetch
    first ? rows only
select
    nl1_0.id,
    nl1_0.board_comment_id,
    nl1_0.board_id,
    nl1_0.body,
    nl1_0.created_at,
    nl1_0.deleted_at,
    nl1_0.question_id,
    nl1_0.subtitle,
    nl1_0.updated_at 
from
    notification_log nl1_0 
where
    nl1_0.id=?

수정된 쿼리

select
    n1_0.id,
    n1_0.created_at,
    n1_0.deleted_at,
    n1_0.member_id,
    nl1_0.id,
    nl1_0.board_comment_id,
    nl1_0.board_id,
    nl1_0.body,
    nl1_0.created_at,
    nl1_0.deleted_at,
    nl1_0.question_id,
    nl1_0.subtitle,
    nl1_0.updated_at,
    n1_0.type,
    n1_0.updated_at 
from
    notification n1_0 
left join
    notification_log nl1_0 
        on nl1_0.id=n1_0.notification_log_id 
where
    n1_0.id<=? 
    and (
        n1_0.member_id=? 
        or n1_0.type=4 
        or n1_0.type=5
    ) 
order by
    n1_0.created_at desc 
offset
    ? rows 
fetch
    first ? rows only

@jaewonLeeKOR jaewonLeeKOR added the ♻️refactor code refactoring label Oct 1, 2024
@jaewonLeeKOR jaewonLeeKOR self-assigned this Oct 1, 2024
@jaewonLeeKOR jaewonLeeKOR linked an issue Oct 1, 2024 that may be closed by this pull request
2 tasks
Copy link
Contributor

@tnals2384 tnals2384 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@youngeun-dev youngeun-dev left a comment

Choose a reason for hiding this comment

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

LGTM !!!

@jaewonLeeKOR jaewonLeeKOR merged commit e5c61d7 into develop Oct 2, 2024
1 check passed
@jaewonLeeKOR jaewonLeeKOR deleted the refactor/#206/notificationN+1 branch October 2, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️refactor code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] 알림 조회 N+1 문제
3 participants