Skip to content

Commit b44cce2

Browse files
committed
feat: 제품 조회 쿼리에 브랜드 정보 로딩 최적화
1 parent 6b01304 commit b44cce2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/infrastructure/product/ProductJpaRepository.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.loopers.domain.product.Product;
44
import jakarta.persistence.LockModeType;
5+
import org.springframework.data.jpa.repository.EntityGraph;
56
import org.springframework.data.jpa.repository.Lock;
67
import org.springframework.data.repository.query.Param;
78
import org.springframework.data.domain.Page;
@@ -18,8 +19,9 @@ public interface ProductJpaRepository extends JpaRepository<Product, Long> {
1819
@Query("SELECT p FROM Product p WHERE p.id IN :ids")
1920
List<Product> findAllByIds(@Param("ids") Collection<Long> ids);
2021

21-
@Query("SELECT p FROM Product p JOIN FETCH p.brand b " +
22-
"WHERE (:brandId IS NULL OR b.id = :brandId)")
22+
@EntityGraph(attributePaths = {"brand"})
23+
@Query("SELECT p FROM Product p " +
24+
"WHERE (:brandId IS NULL OR p.brand.id = :brandId)")
2325
Page<Product> findProducts(@Param("brandId") Long brandId, Pageable pageable);
2426

2527
@Lock(LockModeType.PESSIMISTIC_WRITE)

0 commit comments

Comments
 (0)