Skip to content

[Refactor] n+1 테스트 #317

@sehyeo

Description

@sehyeo

📝 작업 내용 설명

배치사이즈+패치조인 테스트중

UserItemRepository의 JOIN FETCH 코드 참고하여 아래처럼 수정했는데 이 방식이 맞는건지..

    // 오늘 날짜 기준으로 저장된 챌린지만 필터링
    @Query("SELECT uc FROM UserChallenge uc " +
            "JOIN FETCH uc.user u " +
            "JOIN FETCH uc.challenge c " +
            "WHERE u.id = :userId " +
            "AND uc.date = :today " +
            "ORDER BY uc.createdAt DESC")
    List<UserChallenge> findTodayUserChallengesByUserId(
            @Param("userId") Long userId,
            @Param("today") LocalDate today,
            Pageable pageable);

챌린지 홈 조회
(이전)
Image

(JOIN FETCH 추가: JOIN FETCH uc.user u 삭제해도 결과가 비슷하게 나옴.)
(?, ?, ?, ?, ....) 의 문제는 발생하지 않음
Image

✅ 작업할 내용

  • 하이버네이트 로그 n+1 문제 확인하여 페치조인으로 해결

🙋🏻 참고 자료

<참고 자료가 있다면 작성해 주세요>

Metadata

Metadata

Assignees

Labels

🔨 refactor코드 구조 개선, 리팩토링

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions