-
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
[FEAT] 홈 화면 즐겨찾기 API 구현 #75
Conversation
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.
고생 많으셨습니다~~ 다른 api처럼 컨트롤러에 interface 단도 추가해주세요~! 👍 👍
book.addFavorite(favorite); | ||
member.addFavorite(favorite); |
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.
[P2] 이런 연관관계 매핑 로직은 일대다 : 다대일 관계를 풀어주는 중간다리 객체를 생성할 때 함께 넣어주는게 추후 실수할 가능성도 줄이고 코드를 깔끔히 하는데도 더 좋습니다!
방법은 아래 예시를 들어드릴게요~
public static Favorite of(Member member, Book book) { | ||
return new Favorite(member, book); | ||
} |
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.
public static Favorite of(Member member, Book book) { | |
return new Favorite(member, book); | |
} | |
public static Favorite of(Member member, Book book) { | |
Favorite favorite = new Favorite(member, book); | |
book.addFavorite(favorite); | |
member.addFavorite(favorite); | |
return favorite; | |
} |
위에서 얘기한 수정 사항입니다~ 이거를 아마 '연관관계 편의성 설정' 뭐 이렇게 불렀던 것 같은데 혹시 더 궁금하면 한번 찾아보세요 :)
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.
오호 새롭게 알고갑니당 !!!!!
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne |
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.
@ManyToOne | |
@ManyToOne(fetch = FetchType.LAZY) |
[P1] ManyToOne 관계에서는 기본적으로 지연로딩을 설정하는 것이 좋습니다. 안그러면 N+1 문제가 발생할 수 있어요!
이부분은 구글에 검색해보면 자세히 나올건데 간단히 설명드리면
- ManyToOne 관계는 기본적으로 EAGER 즉, 즉시로딩이 기본 설정입니다.
- 따라서 OneToMany 관계에 있는 데이터를 조회할 때 (예를 들면 Member), Member와 연결되어 있는 Favorite 객체도 같이 조회하려고 합니다.
- 근데 Member 1개에는 여러개의 Favorite이 존재하죠?? 그러면 그 Favorite만큼 DB에 쿼리를 날려서 Favorite 데이터를 가져오게 됩니다.
- 단지 Member를 1을 조회하려고 한 것 뿐인데 N번의 쿼리가 날라갔죠?? 이게 N+1 문제입니다.
그래서 지연로딩을 걸면 Member를 조회할 때 Favorite의 프록시 객체(이것도 궁금하면 찾아보세영 ㅋㅋ)가 주입되게 되고, 실제 Favorite을 조회하지 않는 이상 추가적인 쿼리가 발생하지 않게 됩니다!
이것도 따봉만 날리고 가봐라 현예진
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.
ㅋㅋㅋㅋㅋㅋㅋㅋㅋ 왕 자세한 설명 감쟈합니다 ...!!!!!! 바로 반영할게유
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("api/favorite") |
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.
앞에 / 없는거 뭔가... 뭔가.. 불편한데.................
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.
아차차 실수 ......................🤣
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.
수고하셨습니다! 동휘가 리뷰 남겨준 부분 다 반영만 한다면 충분할 것 같아요!
추가로, 즐겨찾기 개수 제한 관련해서 논의 후에 알려드리겠습니다!
📌 관련 이슈
closed #74
✨ 어떤 이유로 변경된 내용인지
🙏 검토 혹은 리뷰어에게 남기고 싶은 말