Skip to content

Commit 8ee1746

Browse files
committed
fix: N+1 문제 해
1 parent 74c6e16 commit 8ee1746

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public interface ProductJpaRepository extends JpaRepository<Product, Long> {
1919
@Query("SELECT p FROM Product p WHERE p.id IN :ids")
2020
List<Product> findAllByIds(@Param("ids") Collection<Long> ids);
2121

22-
@EntityGraph(attributePaths = {"brand"})
23-
@Query("SELECT p FROM Product p " +
24-
"WHERE (:brandId IS NULL OR p.brand.id = :brandId)")
22+
@Query(value = "SELECT p FROM Product p " +
23+
"WHERE (:brandId IS NULL OR p.brand.id = :brandId)",
24+
countQuery = "SELECT COUNT(p) FROM Product p " +
25+
"WHERE (:brandId IS NULL OR p.brand.id = :brandId)")
2526
Page<Product> findProducts(@Param("brandId") Long brandId, Pageable pageable);
2627

2728
@Lock(LockModeType.PESSIMISTIC_WRITE)

0 commit comments

Comments
 (0)