Conversation
요약FollowRepository에 fetch join을 활용한 두 개의 새로운 쿼리 메서드를 추가하여 팔로워/팔로잉 목록 조회 시 관련 엔티티(아바타 포함)를 즉시 로딩하도록 최적화했으며, FollowService에서 이 새로운 메서드들을 사용하도록 업데이트하고, 아바타 시나리오를 포함한 포괄적인 테스트 스위트를 작성했습니다. 변경 사항
예상 코드 리뷰 소요 시간🎯 3 (보통) | ⏱️ ~20분 관련 PR
제안 라벨
제안 리뷰어
시
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In
`@src/main/java/com/example/cp_main_be/domain/social/follow/domain/repository/FollowRepository.java`:
- Around line 16-28: Spotless formatting violations were detected in the
FollowRepository interface; run the formatter and commit the fixes by executing
./gradlew spotlessApply, then review and stage the changed files (notably the
FollowRepository methods findByFollowerWithFollowingAndAvatars, findByFollowing,
and findByFollowingWithFollowerAndAvatars) to ensure the query strings and
annotations conform to the project's Spotless rules before pushing the updated
commit.
In
`@src/main/java/com/example/cp_main_be/domain/social/follow/presentation/FollowController.java`:
- Line 48: There is an unnecessary blank line causing Spotless formatting
failure in FollowController; run the formatter to fix it by executing ./gradlew
spotlessApply and then commit the changes, or manually remove the extra empty
line(s) in the FollowController class (Search for class FollowController or
method definitions in FollowController to locate the offending blank line) so
the file matches the project's Spotless rules.
In
`@src/test/java/com/example/cp_main_be/domain/social/follow/service/FollowServiceTest.java`:
- Line 25: Remove the unused import org.junit.jupiter.api.BeforeEach from the
FollowServiceTest class (FollowServiceTest) to satisfy the linter; either run
./gradlew spotlessApply to auto-fix or manually delete the import line for
BeforeEach so no unused JUnit import remains.
🧹 Nitpick comments (3)
src/main/java/com/example/cp_main_be/domain/social/follow/domain/repository/FollowRepository.java (2)
16-20: 컬렉션 fetch join 사용 시 중복 결과 가능성 검토 필요
avatarList가 컬렉션인 경우,LEFT JOIN FETCH로 인해 카테시안 곱이 발생하여Follow엔티티가 중복될 수 있습니다.DISTINCT키워드 추가를 권장합니다.♻️ 중복 방지를 위한 DISTINCT 추가
- `@Query`("SELECT f FROM Follow f " + + `@Query`("SELECT DISTINCT f FROM Follow f " + "JOIN FETCH f.following u " + "LEFT JOIN FETCH u.avatarList " + "WHERE f.follower = :follower") List<Follow> findByFollowerWithFollowingAndAvatars(`@Param`("follower") User follower);
24-28: 동일하게 DISTINCT 추가 권장위와 동일한 이유로 중복 결과 방지를 위해
DISTINCT추가를 권장합니다.♻️ 제안
- `@Query`("SELECT f FROM Follow f " + + `@Query`("SELECT DISTINCT f FROM Follow f " + "JOIN FETCH f.follower u " + "LEFT JOIN FETCH u.avatarList " + "WHERE f.following = :following") List<Follow> findByFollowingWithFollowerAndAvatars(`@Param`("following") User following);src/test/java/com/example/cp_main_be/domain/social/follow/service/FollowServiceTest.java (1)
54-64: 테스트 헬퍼 메서드에서 Avatar ID 하드코딩 주의
createUserWithAvatar메서드에서 Avatar ID가 항상1L로 하드코딩되어 있습니다. 여러 사용자에게 아바타를 생성할 때 ID 충돌이 발생할 수 있습니다. 현재 테스트에서는 문제가 없지만, 향후 확장 시 고려가 필요합니다.💡 개선 제안
- private User createUserWithAvatar(Long id, String nickname, String avatarImageUrl) { + private static long avatarIdCounter = 1L; + + private User createUserWithAvatar(Long id, String nickname, String avatarImageUrl) { User user = createUser(id, nickname); Avatar avatar = Avatar.builder() - .id(1L) + .id(avatarIdCounter++) .nickname("avatar") .imageUrl(avatarImageUrl) .user(user) .build();
팔로잉, 팔로워 조회 쿼리의 N + 1 문제 해결.
새로 작성한 코드는 다음과 같다.
Summary by CodeRabbit
릴리스 노트
리팩토링
테스트