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

✨feature: Add isLike and itemLikeCount on Items Detail API #83

Merged
merged 6 commits into from
Jun 13, 2023

Conversation

siyeonSon
Copy link
Member

Resolve: #82

@siyeonSon siyeonSon added ✨feature New feature or request 🥇asap As soon as possible labels Jun 11, 2023
@siyeonSon siyeonSon self-assigned this Jun 11, 2023

public boolean isLiked(User user) {
return likes != null ?
likes.stream().anyMatch(like -> like.isLiked(user)) : false;
Copy link
Collaborator

@yunyoung1819 yunyoung1819 Jun 11, 2023

Choose a reason for hiding this comment

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

return likes != null && likes.stream().anyMatch(like -> like.isLiked(user));

이렇게 수정하는게 코드 가독성 측면에서 좀 더 좋은 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

@seonghun-dev
Copy link
Collaborator

seonghun-dev commented Jun 12, 2023

로직상에서는 큰 문제가 없지만 성능 상에 이슈가 발생해서, 일단 이번에는 테스트 코드를 작성해서, 머지를 하고 추후 성능 개선에 대해서 고민하고 추가 이슈를 진행하면 좋을 것 같습니다.

select l1_0.item_id,l1_0.item_like_id,l1_0.created_at,l1_0.modified_at,l1_0.user_id from item_like l1_0 where l1_0.item_id=?

지금 쿼리를 확인하게 되면 Item id에 대해서 item Like 테이블로 조회를 하고 있는데, 만약 Item에 대해서 몇 10만개의 좋아요가 눌리게 되었다면, 서버에서는 몇 10만개의 유저와 비교해야 합니다. 데이터 베이스에서 조회비용, 네트워크 비용등의 많은 부분에서 성능 이슈가 발생하게 될 것 같습니다.

지금 아래와 같이 단순히 /item을 호출하면 아래와 같이 N+1 문제도 존재하고 모든 SQL문이 Join 없이 모든 값을 조회하게 되는데 이런 부분에서 추후 최적화를 진행할 필요가 있을 것 같습니다. (추가 이슈로 진행하면 좋을 것 같습니다.)
Spring Data Jpa만으로 풀기는 어려울 것 같고 Querydsl등으로 풀어나가야 할 것 같습니다.

Hibernate: select i1_0.item_id,i1_0.album_cover_id,i1_0.content,i1_0.created_at,i1_0.modified_at,i1_0.song_id,i1_0.user_id from item i1_0 join item_location i2_0 on i2_0.item_id=i1_0.item_id where st_distance_sphere(i2_0.point,?)<=?
Hibernate: select i1_0.item_location_id,i1_0.created_at,i1_0.item_id,i1_0.modified_at,i1_0.name,i1_0.point,i1_0.village_id from item_location i1_0 where i1_0.item_id=?
Hibernate: select i1_0.item_location_id,i1_0.created_at,i1_0.item_id,i1_0.modified_at,i1_0.name,i1_0.point,i1_0.village_id from item_location i1_0 where i1_0.item_id=?
Hibernate: select u1_0.user_id,u1_0.created_at,u1_0.idfv,u1_0.modified_at,u1_0.nickname from users u1_0 where u1_0.user_id=?
Hibernate: select s1_0.song_id,s1_0.album_id,s1_0.created_at,s1_0.modified_at,s1_0.name from song s1_0 where s1_0.song_id=?
Hibernate: select a1_0.album_id,a1_0.album_cover_id,a1_0.artist_id,a1_0.created_at,a1_0.modified_at,a1_0.name from album a1_0 where a1_0.album_id=?
Hibernate: select a1_0.artist_id,a1_0.created_at,a1_0.modified_at,a1_0.name from artist a1_0 where a1_0.artist_id=?
Hibernate: select a1_0.album_cover_id,a1_0.album_image,a1_0.album_thumbnail,a1_0.created_at,a1_0.modified_at from album_cover a1_0 where a1_0.album_cover_id=?
Hibernate: select g1_0.song_id,g1_0.song_genre_id,g1_0.created_at,g1_0.genre_id,g1_0.modified_at from song_genre g1_0 where g1_0.song_id=?
Hibernate: select g1_0.genre_id,g1_0.created_at,g1_0.modified_at,g1_0.name from genre g1_0 where g1_0.genre_id=?
Hibernate: select g1_0.genre_id,g1_0.created_at,g1_0.modified_at,g1_0.name from genre g1_0 where g1_0.genre_id=?
Hibernate: select l1_0.item_id,l1_0.item_like_id,l1_0.created_at,l1_0.modified_at,l1_0.user_id from item_like l1_0 where l1_0.item_id=?
Hibernate: select u1_0.user_id,u1_0.created_at,u1_0.idfv,u1_0.modified_at,u1_0.nickname from users u1_0 where u1_0.user_id=?
Hibernate: select a1_0.album_cover_id,a1_0.album_image,a1_0.album_thumbnail,a1_0.created_at,a1_0.modified_at from album_cover a1_0 where a1_0.album_cover_id=?
Hibernate: select l1_0.item_id,l1_0.item_like_id,l1_0.created_at,l1_0.modified_at,l1_0.user_id from item_like l1_0 where l1_0.item_id=?

@siyeonSon siyeonSon merged commit c33f8c1 into main Jun 13, 2023
@siyeonSon siyeonSon deleted the feature/is-liked branch June 13, 2023 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🥇asap As soon as possible ✨feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add isLike and itemLikeCount on Items Detail API
3 participants