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

카페 이미지 Fetch Join 시 Inner Join 하도록 변경 #468

Merged
merged 16 commits into from
Sep 26, 2023

Conversation

nuyh99
Copy link
Collaborator

@nuyh99 nuyh99 commented Sep 20, 2023

#️⃣ 연관된 이슈

📝 작업 내용

  • 테스트 환경 설정에서 빠진 batch size 추가(팀시티에도 없더라구요...)
  • CafeRankGenerator 제거(Pageableoffset 사용)
  • cafe.images.url 조인할 때 outer join -> inner join으로 변경 (패치 조인 가능)
    • 이미지 최소 1개 이상 포함하도록 검증 로직 추가

@nuyh99 nuyh99 self-assigned this Sep 20, 2023
@nuyh99 nuyh99 added the BE 개발은 백이징 label Sep 20, 2023
@nuyh99 nuyh99 force-pushed the feat/467-inner-join branch from 515f684 to 7d5fbde Compare September 20, 2023 14:26
@nuyh99 nuyh99 changed the title Feat/467 inner join 카페 이미지 Fetch Join 시 Inner Join 하도록 변경 Sep 20, 2023
Copy link
Collaborator

@green-kong green-kong left a comment

Choose a reason for hiding this comment

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

연어덕에 전반적으로 코드가 많이 좋아졌네요!
감사합니다!

Comment on lines +4 to +9
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

감사합니다!

Comment on lines +79 to 81
public Cafe(final String name, final String address, final Images images, final Detail detail) {
this(null, name, address, images, detail, 0);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

감사합니다2

Comment on lines 15 to 22
@Query("""
select m
from Member m
left join fetch m.unViewedCafes uvc
left join fetch uvc.cafe
where m.id = :id
SELECT m
FROM Member m
LEFT JOIN FETCH m.unViewedCafes uvc
LEFT JOIN FETCH uvc.cafe
WHERE m.id = :id
""")
Optional<Member> findById(@Param("id") String id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

흐음. 여기도 inner join 해도 되지 않나요???'
문제가 없는 부분이라 대문자 패치만 하신걸까요??

아 대문자 패치는 감사합니다!3

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

UnViewedCafeCafe는 1:1 not null 관계이기 때문에 inner join이 좋을 것 같아요!

@@ -35,8 +32,6 @@ public enum ErrorCode {
NOT_EXISTED_OAUTH_PROVIDER("O2", "잘못된 Provider Name 입니다."),
NOT_EXISTED_OAUTH_CLIENT("O3", "일치하는 OAuthClient가 존재하지 않습니다."),

RANK_OUT_OF_BOUNDS("R1", format("좋아요 개수 랭킹 범위를 벗어나는 요청입니다. 좋아요 랭킹은 %d위까지 가능합니다. 요청의 페이지 확인이 필요합니다.", MAX_RANK)),

Copy link
Collaborator

Choose a reason for hiding this comment

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

랭킹 범위 수정 감사합니다~

@@ -22,3 +22,4 @@ spring.flyway.enabled=true
spring.flyway.baseline-version=20230901153300
spring.flyway.baseline-on-migrate=true
spring.flyway.out-of-order=true
spring.jpa.properties.hibernate.default_batch_fetch_size=1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

굿~ 테스트 쪽을 신경 못 썼네요..

SELECT m
FROM Member m
LEFT JOIN FETCH m.unViewedCafes uvc
JOIN FETCH uvc.cafe
Copy link
Collaborator

Choose a reason for hiding this comment

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

헉 이 부분 때문에 테스트가 와장창 깨지는 것 같아요!
테스트에서 member를 찾지 못하고 있네요

Copy link
Collaborator

Choose a reason for hiding this comment

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

😹

Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 진행될 경우에 uvc가 없는 멤버는 조회되지 않을 것 같네요 ...

음 . . findbyid 메소드 자체를 오버로딩해서 사용해야 될 수도 있겠는데요 ?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

메서드를 따로 분리했습니다

Copy link
Collaborator

@donghae-kim donghae-kim left a comment

Choose a reason for hiding this comment

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

고생하셨어요 연어~

도치 폴로가 이미 좋은 코멘트를 남겨줬었네요!

현재 테스트 코드가 깨지고있는 fetch join 시 inner join에 대해서 같이 이야기하면서 해결하면 좋을 것 같아요! 일단 inner조인 처리를 하려는 이유가 궁금합니다! 또한 코멘트에 남겼듯이 지금과 같은 방식대로 진행하려면 메소드를 오버로딩 해서 처리해도 될 것 같은데 연어의 의견도 궁금하네용

SELECT c
FROM Cafe c
JOIN FETCH c.images.urls
WHERE c.id = :cafeId
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

코멘트 달아주신

cafe.images.url 조인할 때 outer join -> inner join으로 변경 (패치 조인 가능) 

에서 패치 조인 가능 이라는게 어떤 건가요? outer join -> inner join으로 변경해서 패치조인이 가능해졌다 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

outer join -> inner join으로 변경해서 패치조인이 가능해졌다 ? 말이 맞습니다!

@@ -22,7 +23,7 @@ public class Detail {
public static final int PHONE_MAX_LENGTH = 20;

@ElementCollection(fetch = FetchType.LAZY)
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 images 처럼 fetchtype 생략해도 되겠네요

SELECT m
FROM Member m
LEFT JOIN FETCH m.unViewedCafes uvc
JOIN FETCH uvc.cafe
Copy link
Collaborator

Choose a reason for hiding this comment

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

😹

response.add(CafeRankResponse.of(++rank, cafe));
}

return response;
Copy link
Collaborator

Choose a reason for hiding this comment

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

RankGenerator를 없애주셨군요 👍

SELECT m
FROM Member m
LEFT JOIN FETCH m.unViewedCafes uvc
JOIN FETCH uvc.cafe
Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 진행될 경우에 uvc가 없는 멤버는 조회되지 않을 것 같네요 ...

음 . . findbyid 메소드 자체를 오버로딩해서 사용해야 될 수도 있겠는데요 ?!

@solo5star solo5star linked an issue Sep 22, 2023 that may be closed by this pull request
@nuyh99 nuyh99 force-pushed the feat/467-inner-join branch from f9bd513 to 8642078 Compare September 26, 2023 07:47
Copy link
Collaborator

@donghae-kim donghae-kim left a comment

Choose a reason for hiding this comment

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

고생했어요 연어

@nuyh99 nuyh99 merged commit f4b6dad into dev Sep 26, 2023
@nuyh99 nuyh99 deleted the feat/467-inner-join branch September 26, 2023 08:25
@nuyh99 nuyh99 restored the feat/467-inner-join branch September 26, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 개발은 백이징
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

카페가 이미지를 최소 1개 이상 포함하도록 한다.
5 participants