-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] refactor: 상품 목록 조회 api 성능 개선 #685
Conversation
…viewCountDesc 메소드를 findAllByCategory메소드로 통합 및 반환타입 수정 - ReviewCount 반정규화로 인해 메소드 분리 필요성 없어짐 - ReviewCount를 위한 join 쿼리 제거 - 페이징에 대한 자세한 정보(ex. 전체 페이지 수등) 필요없기 때문에 반환값을 Page에서 Slice로 수정
…Next값으로 response 만들도록 수정
(기존) sort=price,asc&page=1 (수정) sort=price,asc&id=5
3-2 동적 쿼리 사용 (criteria + specification)고민 과정
SELECT
p.id, p.name, p.price, p.image, p.average_rating, p.review_count
FROM product p
JOIN product p2
ON p2.id = :lastProductId
WHERE
p.category_id = 2 AND
(
(p.price = p2.price AND p.id < :lastProductId) OR
p.price > p2.price
)
ORDER BY p.price, p.id DESC
LIMIT 11; 위와 같은 기존 쿼리를 살려서 join을 하고자 했으나,
SELECT
p.id, p.name, p.price, p.image, p.average_rating, p.review_count
FROM product p
WHERE
p.category_id = 2 AND
(
(p.price = (select price from product where id = :lastProductId) AND p.id < :lastProductId)
OR p.price > (select price from product where id = :lastProductId)
)
ORDER BY p.price, p.id DESC
LIMIT 11; 1)에서 Join을 하는 이유가 lastProduct의 price가 필요해서 였기 때문에,
위 모든 행위의 이유는 딱 'lastProduct의 price가 필요'해서 -> 그냥 findById로 가져오는 건 어떨까? 결과 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
backend/src/main/java/com/funeat/common/repository/BaseRepository.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간단한 것만 수정하면 될 것 같아요~
고생하셨습니다~
backend/src/main/java/com/funeat/product/persistence/ProductSpecification.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/funeat/product/presentation/ProductApiController.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/funeat/product/presentation/ProductController.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코멘트 몇 개 남겨두었습니다.
확인해주세요~~!~!
backend/src/main/java/com/funeat/product/persistence/ProductSpecification.java
Show resolved
Hide resolved
backend/src/main/java/com/funeat/product/presentation/ProductApiController.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/funeat/common/repository/BaseRepository.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/funeat/product/persistence/ProductRepository.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요~~
Issue
✨ 구현한 기능
상품 목록 조회 Api 성능 개선
(기존)
(1차 개선)
(2차 개선) 인덱스
(3차 개선) 동적 쿼리 ???
📢 논의하고 싶은 내용
Pageable을 걷어내다보니 정렬조건에 따라 메소드가 무려 10개가 나옵니다.
동적쿼리를 위한 QueryDsl 도입이 시급!
🎸 기타
⏰ 일정