Skip to content
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] 리뷰 목록 카테고리 조회 시 네이티브 쿼리를 사용하도록 변경 #344

Closed

Conversation

skylar1220
Copy link
Contributor

@skylar1220 skylar1220 commented Aug 13, 2024


🚀 어떤 기능을 구현했나요 ?

  • 리뷰 목록 카테고리 조회 시 네이티브 쿼리를 사용하도록 변경합니다.

🔥 어떻게 해결했나요 ?

  • 리뷰 목록 카테고리 조회 시 네이티브 쿼리를 사용하여 쿼리를 한 번만 나가게 했습니다.

📝 어떤 부분에 집중해서 리뷰해야 할까요?

  • 네이티브 쿼리가 잘 쓰여졌는지 봐주쎄여~

📚 참고 자료, 할 말

  • 저번에 미뤄둔 네이티브 쿼리 리팩토링 이제 합니당..ㅎㅎ
  • 템플릿 생성에 대해서 fixture가 있어야겠네요!

Copy link

github-actions bot commented Aug 13, 2024

Test Results

58 tests   58 ✅  2s ⏱️
22 suites   0 💤
22 files     0 ❌

Results for commit f4119f3.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@donghoony donghoony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아자아자!

WHERE ca.review_id = :reviewId
AND o.option_type = :#{#optionType.name()}
""", nativeQuery = true)
List<OptionItem> findByOptionTypeAndReviewId(long reviewId, OptionType optionType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 언급 순서와 파라미터 순서를 일치시켜주세요 (review가 더 앞에 오는 게 좋겠네요~)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쿼리 굿 ! Inner join과 Left join, Outer join과도 비교해보고 어떤 걸 쓰는 것이 성능 상 이점이 있는지도 공부해보면 좋아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 교집합만 필요한 경우니 inner join을 적용해봐도 좋겠네요!

@@ -170,26 +168,13 @@ public ReceivedReviewsResponse2 findReceivedReviews2(String groupAccessCode) {
}

private ReceivedReviewResponse2 createReceivedReviewResponse2(Review2 review) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실히 레포에서 가져오는 게 정해지니 서비스가 깔끔해지네요 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

역시 JPA를 쓸 거면 확실히 쓰는게 좋군요😂

@@ -77,4 +96,47 @@ class OptionItemRepositoryTest {
assertThat(actual).extracting(OptionItem::getId).containsExactly(optionId3, optionId1);
}

@Test
void 리뷰_아이디와_옵션_타입으로_선택한_옵션_아이템을_불러온다() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두 번째 테스트가 첫 번째와 격리되고 있지 않아보입니다. 저는 테스트를 실패하는데 커비는 성공하나요 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 저는 성공합니다! DataJpaTest로 롤백은 되는데 이미 증가한 id는 다시 초기화 되지 않는 현상이 있습니다.
하지만 각 객체에서 getId() 방식으로 값을 불러다 쓰기 때문에 테스트에 영향은 없도록 테스트 로직을 짰습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BE] 리뷰 목록 카테고리 조회 시 네이티브 쿼리를 사용하도록 변경한다.
2 participants