Skip to content

Conversation

@joyewon0705
Copy link
Collaborator

📌 개요

  • 게시글(Post)과 댓글(Comment) 도메인의 쿼리 효율 개선 및 패키지 구조 정리를 진행했습니다.
  • N+1 문제를 최소화하고, 도메인 간 의존도를 줄여 유지보수성과 확장성을 높이는 데 초점을 맞췄습니다.

🔨 작업 내용

1. PostRepositoryImpl 개선

  • 검색/정렬 로직 리팩터링

    • 검색 조건, 정렬 조건, 카운트 로직을 메서드로 분리하여 가독성 향상
    • likeCount, bookmarkCount, commentCount 집계를 서브쿼리로 분리 → N+1 방지
  • 정렬 처리 개선

    • DB에서는 엔티티 필드만 정렬
    • 통계 필드(likeCount, bookmarkCount, commentCount)는 Java 메모리 단에서 정렬
  • 카테고리 주입 최적화

    • PostId 기반 IN 쿼리 1회로 조회 후 DTO에 매핑
  • Page 객체 반환 구조 개선

    • 전체 조회 → 카테고리 주입 → 통계 기반 정렬 → count 쿼리 실행

2. CommentRepositoryImpl 개선

  • 부모/자식 댓글 조회 로직 개선

    • 부모 댓글 페이징 → 자식 댓글 일괄 조회 후 매핑
  • likeCount 조회 최적화

    • 부모/자식 댓글 ID를 한 번에 모아서 groupBy IN 쿼리 1회 실행
  • 정렬 처리 개선

    • 엔티티 필드(createdAt, updatedAt)는 DB에서 정렬
    • likeCount는 메모리에서 후처리 정렬
  • 내부 메서드 분리

    • fetchComments, fetchLikeCounts, mapChildrenToParents, sortInMemoryIfNeeded 등 세부 책임 분리

3. board 패키지 구조 개선 (03626bd)

  • 도메인 단위로 패키지 분리

    • board.comment.* : 댓글 관련 Controller, DTO, Entity, Repository, Service
    • board.post.* : 게시글 관련 Controller, DTO, Entity, Repository, Service
    • board.common.* : 공통 DTO (PageResponse, AuthorResponse 등)
  • 테스트 코드 리팩터링

    • 변경된 패키지 경로에 맞게 CommentControllerTest, PostControllerTest, CommentServiceTest, PostServiceTest 수정
  • User 엔티티 참조 변경

    • 기존 com.back.domain.board.entity.* import → 세분화된 board.comment.entity, board.post.entity로 교체

🔗 관련 이슈

Closes #166

📝 참고 사항

  • QueryDSL Q클래스 재생성 필요

✅ 체크리스트

  • 기능 동작 확인
  • 테스트 코드 작성
  • 문서/주석 추가 및 최신화

@github-actions github-actions bot changed the title Refactor: 게시판(Post/Comment) 레포지토리 및 패키지 구조 개선 Refactor: 게시판(Post/Comment) 레포지토리 및 패키지 구조 개선 (#166) Oct 4, 2025
@joyewon0705 joyewon0705 merged commit 7120628 into dev Oct 4, 2025
2 checks passed
@github-actions github-actions bot deleted the Refactor/166 branch October 4, 2025 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants