2021 10 21 놀토로그
2021-10-21 - 놀토 로그
현재 놀토 단일 피드 조회 시 현재 발생하는 sql 로그
요청한 id에 따라 글 조회해오기
00:35:15.023 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
select
comment0_.id as id1_0_0_,
user1_.id as id1_7_1_,
feed2_.id as id1_2_2_,
comment0_.created_date as created_2_0_0_,
comment0_.modified_date as modified3_0_0_,
comment0_.author_id as author_i6_0_0_,
comment0_.content as content4_0_0_,
comment0_.feed_id as feed_id7_0_0_,
comment0_.helper as helper5_0_0_,
comment0_.parent_id as parent_i8_0_0_,
user1_.created_date as created_2_7_1_,
user1_.modified_date as modified3_7_1_,
user1_.bio as bio4_7_1_,
user1_.image_url as image_ur5_7_1_,
user1_.nick_name as nick_nam6_7_1_,
user1_.social_id as social_i7_7_1_,
user1_.social_type as social_t8_7_1_,
feed2_.created_date as created_2_2_2_,
feed2_.modified_date as modified3_2_2_,
feed2_.author_id as author_12_2_2_,
feed2_.content as content4_2_2_,
feed2_.deployed_url as deployed5_2_2_,
feed2_.is_sos as is_sos6_2_2_,
feed2_.step as step7_2_2_,
feed2_.storage_url as storage_8_2_2_,
feed2_.thumbnail_url as thumbnai9_2_2_,
feed2_.title as title10_2_2_,
feed2_.views as views11_2_2_
from
comment comment0_
inner join
user user1_
on comment0_.author_id=user1_.id
inner join
feed feed2_
on comment0_.feed_id=feed2_.id
where
comment0_.feed_id=?
and (
comment0_.parent_id is null
)
order by
comment0_.created_date desc,
comment0_.id desc
00:35:15.023 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [36]
00:35:15.025 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
피드에 달린 커멘트를 들고 오는 과정
List<comments> 가져온 후, likes를 Lazy Loading (N+1 쿼리 발생)
- Dto에서 likes.size() 를 조회하는 작업을 거치면서 lazy loading을 해옴
public List<CommentResponse> findAllByFeedId(Long feedId, User user) {
List<Comment> comments = commentRepository.findAllByFeedIdAndParentCommentIdIsNull(feedId);
return CommentResponse.toList(comments, user);
}
public static List<CommentResponse> toList(List<Comment> comments, User user) {
return comments.stream()
.map(comment -> CommentResponse.of(comment, user.isCommentLiked(comment)))
.collect(Collectors.toList());
}
public static CommentResponse of(Comment comment, boolean isCommentLiked) {
return new CommentResponse(
comment.getId(),
comment.getContent(),
comment.isHelper(),
comment.likesCount(),
isCommentLiked,
comment.isFeedAuthor(),
comment.getCreatedDate(),
comment.isModified(),
AuthorResponse.of(comment.getAuthor())
);
}
select
likes0_.comment_id as comment_2_1_0_,
likes0_.id as id1_1_0_,
likes0_.id as id1_1_1_,
likes0_.comment_id as comment_2_1_1_,
likes0_.user_id as user_id3_1_1_
from
comment_like likes0_
where
likes0_.comment_id=?
00:35:15.025 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [594]
00:35:15.025 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
select
likes0_.comment_id as comment_2_1_0_,
likes0_.id as id1_1_0_,
likes0_.id as id1_1_1_,
likes0_.comment_id as comment_2_1_1_,
likes0_.user_id as user_id3_1_1_
from
comment_like likes0_
where
likes0_.comment_id=?
00:35:15.025 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [593]
00:35:15.025 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
select
likes0_.comment_id as comment_2_1_0_,
likes0_.id as id1_1_0_,
likes0_.id as id1_1_1_,
likes0_.comment_id as comment_2_1_1_,
likes0_.user_id as user_id3_1_1_
from
comment_like likes0_
where
likes0_.comment_id=?
00:35:15.025 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [443]
00:35:15.026 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
select
likes0_.comment_id as comment_2_1_0_,
likes0_.id as id1_1_0_,
likes0_.id as id1_1_1_,
likes0_.comment_id as comment_2_1_1_,
likes0_.user_id as user_id3_1_1_
from
comment_like likes0_
where
likes0_.comment_id=?
00:35:15.026 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [255]
00:35:15.026 [DEBUG] [http-nio-8080-exec-2] [org.hibernate.SQL] -
select
likes0_.comment_id as comment_2_1_0_,
likes0_.id as id1_1_0_,
likes0_.id as id1_1_1_,
likes0_.comment_id as comment_2_1_1_,
likes0_.user_id as user_id3_1_1_
from
comment_like likes0_
where
likes0_.comment_id=?
00:35:15.026 [TRACE] [http-nio-8080-exec-2] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [253]
커멘트들도 들고와야지
00:35:15.088 [DEBUG] [http-nio-8080-exec-6] [org.hibernate.SQL] -
select
comment0_.id as id1_0_0_,
user1_.id as id1_7_1_,
feed2_.id as id1_2_2_,
comment0_.created_date as created_2_0_0_,
comment0_.modified_date as modified3_0_0_,
comment0_.author_id as author_i6_0_0_,
comment0_.content as content4_0_0_,
comment0_.feed_id as feed_id7_0_0_,
comment0_.helper as helper5_0_0_,
comment0_.parent_id as parent_i8_0_0_,
user1_.created_date as created_2_7_1_,
user1_.modified_date as modified3_7_1_,
user1_.bio as bio4_7_1_,
user1_.image_url as image_ur5_7_1_,
user1_.nick_name as nick_nam6_7_1_,
user1_.social_id as social_i7_7_1_,
user1_.social_type as social_t8_7_1_,
feed2_.created_date as created_2_2_2_,
feed2_.modified_date as modified3_2_2_,
feed2_.author_id as author_12_2_2_,
feed2_.content as content4_2_2_,
feed2_.deployed_url as deployed5_2_2_,
feed2_.is_sos as is_sos6_2_2_,
feed2_.step as step7_2_2_,
feed2_.storage_url as storage_8_2_2_,
feed2_.thumbnail_url as thumbnai9_2_2_,
feed2_.title as title10_2_2_,
feed2_.views as views11_2_2_
from
comment comment0_
inner join
user user1_
on comment0_.author_id=user1_.id
inner join
feed feed2_
on comment0_.feed_id=feed2_.id
where
comment0_.feed_id=?
and comment0_.parent_id=?
order by
comment0_.created_date desc,
comment0_.id desc
00:35:15.088 [TRACE] [http-nio-8080-exec-6] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [36]
00:35:15.088 [TRACE] [http-nio-8080-exec-6] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [2] as [BIGINT] - [594]
00:35:15.089 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
feed0_.id as id1_2_0_,
feed0_.created_date as created_2_2_0_,
feed0_.modified_date as modified3_2_0_,
feed0_.author_id as author_12_2_0_,
feed0_.content as content4_2_0_,
feed0_.deployed_url as deployed5_2_0_,
feed0_.is_sos as is_sos6_2_0_,
feed0_.step as step7_2_0_,
feed0_.storage_url as storage_8_2_0_,
feed0_.thumbnail_url as thumbnai9_2_0_,
feed0_.title as title10_2_0_,
feed0_.views as views11_2_0_
from
feed feed0_
where
feed0_.id=?
00:35:15.089 [TRACE] [http-nio-8080-exec-3] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [36]
00:35:15.089 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
user0_.id as id1_7_0_,
user0_.created_date as created_2_7_0_,
user0_.modified_date as modified3_7_0_,
user0_.bio as bio4_7_0_,
user0_.image_url as image_ur5_7_0_,
user0_.nick_name as nick_nam6_7_0_,
user0_.social_id as social_i7_7_0_,
user0_.social_type as social_t8_7_0_
from
user user0_
where
user0_.id=?
00:35:15.089 [TRACE] [http-nio-8080-exec-3] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [30]
feedTech로 부터 tech를 하나하나 id를 기반으로 가져옴
- BatchSize를 도입하여 필요한 tech의 id를 in 절로 촤르르 가져오게 할 예정
00:35:15.090 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
feedtechs0_.feed_id as feed_id2_3_0_,
feedtechs0_.id as id1_3_0_,
feedtechs0_.id as id1_3_1_,
feedtechs0_.feed_id as feed_id2_3_1_,
feedtechs0_.tech_id as tech_id3_3_1_
from
feed_tech feedtechs0_
where
feedtechs0_.feed_id=?
00:35:15.090 [TRACE] [http-nio-8080-exec-3] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [36]
00:35:15.090 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
tech0_.id as id1_6_0_,
tech0_.name as name2_6_0_
from
tech tech0_
where
tech0_.id=?
00:35:15.090 [TRACE] [http-nio-8080-exec-3] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [25]
00:35:15.091 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
tech0_.id as id1_6_0_,
tech0_.name as name2_6_0_
from
tech tech0_
where
tech0_.id=?
00:35:15.091 [TRACE] [http-nio-8080-exec-3] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [1160]
00:35:15.091 [DEBUG] [http-nio-8080-exec-3] [org.hibernate.SQL] -
select
tech0_.id as id1_6_0_,
tech0_.name as name2_6_0_
from
tech tech0_
where
tech0_.id=?
답글은 reply_id 별로 프론트에서 요청보내서 현재로썬 이렇게 나옴
- 이렇게 생긴거 답글수 만큼 쿼리
00:35:15.092 [DEBUG] [http-nio-8080-exec-1] [org.hibernate.SQL] -
select
comment0_.id as id1_0_0_,
user1_.id as id1_7_1_,
feed2_.id as id1_2_2_,
comment0_.created_date as created_2_0_0_,
comment0_.modified_date as modified3_0_0_,
comment0_.author_id as author_i6_0_0_,
comment0_.content as content4_0_0_,
comment0_.feed_id as feed_id7_0_0_,
comment0_.helper as helper5_0_0_,
comment0_.parent_id as parent_i8_0_0_,
user1_.created_date as created_2_7_1_,
user1_.modified_date as modified3_7_1_,
user1_.bio as bio4_7_1_,
user1_.image_url as image_ur5_7_1_,
user1_.nick_name as nick_nam6_7_1_,
user1_.social_id as social_i7_7_1_,
user1_.social_type as social_t8_7_1_,
feed2_.created_date as created_2_2_2_,
feed2_.modified_date as modified3_2_2_,
feed2_.author_id as author_12_2_2_,
feed2_.content as content4_2_2_,
feed2_.deployed_url as deployed5_2_2_,
feed2_.is_sos as is_sos6_2_2_,
feed2_.step as step7_2_2_,
feed2_.storage_url as storage_8_2_2_,
feed2_.thumbnail_url as thumbnai9_2_2_,
feed2_.title as title10_2_2_,
feed2_.views as views11_2_2_
from
comment comment0_
inner join
user user1_
on comment0_.author_id=user1_.id
inner join
feed feed2_
on comment0_.feed_id=feed2_.id
where
comment0_.feed_id=?
and comment0_.parent_id=?
order by
comment0_.created_date desc,
comment0_.id desc
00:35:15.092 [TRACE] [http-nio-8080-exec-1] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [36]
00:35:15.092 [TRACE] [http-nio-8080-exec-1] [o.h.type.descriptor.sql.BasicBinder] - binding parameter [2] as [BIGINT] - [593]