Skip to content

Commit 7fe5739

Browse files
committed
fix:coderabbit 수정 사항
1 parent 54b1d1b commit 7fe5739

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/main/java/com/ongil/backend/domain/brand/repository/BrandRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface BrandRepository extends JpaRepository<Brand, Long> {
1414
List<Brand> findAllOrderByName();
1515

1616
@Query(value = "SELECT b.* FROM brands b " +
17-
"WHERE EXISTS (SELECT 1 FROM products p WHERE p.brand_id = b.id AND p.on_sale = true) " +
17+
"WHERE EXISTS (SELECT 1 FROM products p WHERE p.brand_id = b.id AND p.on_sale = true AND p.product_type <> 'SPECIAL_SALE') " +
1818
"ORDER BY RAND() LIMIT 3", nativeQuery = true)
1919
List<Brand> findRandomBrands();
2020
}

src/main/java/com/ongil/backend/domain/category/service/CategoryService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.Collections;
5+
import java.util.HashSet;
56
import java.util.List;
7+
import java.util.Set;
68
import java.util.stream.Collectors;
79

810
import org.springframework.stereotype.Service;
@@ -46,11 +48,13 @@ public List<CategoryResponse> getAllCategories() {
4648

4749
// Cache Miss → DB 조회
4850
List<Category> parentCategories = categoryRepository.findAllParentCategoriesWithSub();
51+
Set<Long> activeCategoryIds = new HashSet<>(productRepository.findCategoryIdsWithOnSaleProducts());
52+
4953
List<CategoryResponse> response = parentCategories.stream()
5054
.map(parent -> {
51-
// 상품이 있는 하위 카테고리만 필터링
55+
// 판매 중인 상품이 있는 하위 카테고리만 필터링
5256
List<SubCategoryResponse> filteredSubs = parent.getSubCategories().stream()
53-
.filter(sub -> productRepository.existsByCategoryIdAndOnSaleTrue(sub.getId()))
57+
.filter(sub -> activeCategoryIds.contains(sub.getId()))
5458
.map(categoryConverter::toSubCategoryResponse)
5559
.collect(Collectors.toList());
5660

@@ -100,9 +104,10 @@ public List<CategoryRandomResponse> getRandomCategories(int count) {
100104
// 추천 하위 카테고리 조회 (상품이 있는 하위 카테고리만)
101105
public List<CategorySimpleResponse> getRecommendedSubCategories(int count) {
102106
List<Category> subCategories = categoryRepository.findAllSubCategories();
107+
Set<Long> activeCategoryIds = new HashSet<>(productRepository.findCategoryIdsWithOnSaleProducts());
103108

104109
return subCategories.stream()
105-
.filter(category -> productRepository.existsByCategoryIdAndOnSaleTrue(category.getId()))
110+
.filter(category -> activeCategoryIds.contains(category.getId()))
106111
.limit(count)
107112
.map(categoryConverter::toSimpleResponse)
108113
.collect(Collectors.toList());

src/main/java/com/ongil/backend/domain/product/repository/ProductRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ List<Product> findRecommendedProducts(
238238
// 특정 카테고리를 사용하는 상품이 있는지 확인
239239
boolean existsByCategoryId(Long categoryId);
240240

241-
// 특정 카테고리에 판매 중인 상품이 있는지 확인
242-
boolean existsByCategoryIdAndOnSaleTrue(Long categoryId);
241+
// 판매 중인 상품이 존재하는 카테고리 ID 목록 일괄 조회
242+
@Query("SELECT DISTINCT p.category.id FROM Product p WHERE p.onSale = true")
243+
List<Long> findCategoryIdsWithOnSaleProducts();
243244
}

0 commit comments

Comments
 (0)