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

메인페이지 쿼리(구조) 개선 필요 #83

Open
NuhGnod opened this issue Jan 4, 2024 · 1 comment
Open

메인페이지 쿼리(구조) 개선 필요 #83

NuhGnod opened this issue Jan 4, 2024 · 1 comment
Labels
enhancement New feature or request refactor refactor something

Comments

@NuhGnod
Copy link
Contributor

NuhGnod commented Jan 4, 2024

현재 메인 페이지 조회 요청 로직

  1. post 엔티티 N개 조회
  2. 각 post 엔티티에 연관된 댓글 엔티티 개수 조회
  3. 응답값에 댓글 수 포함하여 반환

문제점

따라서, N+N 개의 요청 발생
->
게시글 10개가 있다면, 댓글 수 값을 알기 위해 추가적으로 10번의 댓글 테이블 조회 쿼리가 발생한다.

@NuhGnod NuhGnod added enhancement New feature or request refactor refactor something labels Jan 4, 2024
@NuhGnod
Copy link
Contributor Author

NuhGnod commented Mar 1, 2024

    select p.*, count(c.id) as count  from post as p
left join comment as c on p.id = c.post_id
GROUP BY p.id;

NuhGnod added a commit that referenced this issue Mar 1, 2024
close #105
쿼리만 개선, 실제로 repository에서 dto로 projection하는 작업 필요.
see #83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor refactor something
Projects
None yet
Development

No branches or pull requests

1 participant