원인 분석


해결 방안


  1. 한방 쿼리를 사용하지 않고 여러개의 쿼리로 나누어 데이터를 가져오는 방법
  2. 조건에 따라 다른 쿼리를 사용하면서 각각의 조건에 맞게 쿼리 최적화

⇒ 저는 2번의 방식과 1번 방식을 혼합하여 리팩토링을 진행하였습니다.

변경 전 코드

@Transactional(readOnly = true)
public Page<ProfilePageResponse> searchProfiles(ProfileSearch profileSearch, Pageable pageable) {
    return profileDomainService.searchProfiles(profileSearch, pageable);
}

변경 후 코드

@Transactional(readOnly = true)
    public Page<ProfilePageResponse> searchProfiles(ProfileSearch profileSearch, Pageable pageable) {
        if(profileSearch.isEmpty()){
            return profileDomainService.getProfileList(pageable);
        }
        return profileDomainService.searchProfiles(profileSearch, pageable);
    }