When loading posts from the posts list, 1 query to find posts that meet the conditions, 1 count query for paging, and 1 query to count comment notifications(Notification function works through HandlerInterceptor) are created.
However, looking at the log, after the 3 queries above, 3 duplicate queries appear the same again, but I don t know why.
Below is the relevant code.
// PostRepositoryImpl
// function called by controller
public Page<BoardResponseForm> selectPostList(String boardCategory, String category, Pageable pageable) {
List<BoardResponseForm> content = getPostList(boardCategory, category, pageable);
Long count = getCount(boardCategory, category);
return new PageImpl<>(content, pageable, count);
}
private Long getCount(String boardCategory, String category) {
Long count = jpaQueryFactory
.select(post.count())
.from(post)
.where(checkBoardCategory(boardCategory),
checkPostCategory(category))
.fetchOne();
return count;
}
private List<BoardResponseForm> getPostList(String boardCategory, String category, Pageable pageable) {
List<BoardResponseForm> content = jpaQueryFactory
.select(new QBoardResponseForm(
post.id,
post.viewCount,
post.likeCount,
post.commentCount,
post.title,
post.postCategory,
account.nickname,
post.publishedDateTime))
.from(post)
.leftJoin(post.author, account)
.where(checkBoardCategory(boardCategory),
checkPostCategory(category))
.orderBy(post.id.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
return content;
}
private BooleanExpression checkBoardCategory(String boardCategory) {
return post.boardCategory.eq(boardCategory);
}
private BooleanExpression checkPostCategory(String category) {
return StringUtils.hasText(category) ? post.postCategory.eq(category) : null;
}
Below is the query log.
After 3 queries go out, the same 3 queries come again.
2023-08-13 11:39:36.636 DEBUG 1592 --- [io-8080-exec-10] org.hibernate.SQL :
select
post0_.id as col_0_0_,
post0_.view_count as col_1_0_,
post0_.like_count as col_2_0_,
post0_.comment_count as col_3_0_,
post0_.title as col_4_0_,
post0_.post_category as col_5_0_,
account1_.nickname as col_6_0_,
post0_.published_date_time as col_7_0_
from
post post0_
left outer join
account account1_
on post0_.author_id=account1_.id
where
(
post0_.title like ? escape !
or post0_.content like ? escape !
or account1_.nickname like ? escape !
)
and post0_.board_category=?
and post0_.post_category=?
order by
post0_.id desc limit ?
2023-08-13 11:39:36.636 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%test%]
2023-08-13 11:39:36.636 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CLOB] - [%test%]
2023-08-13 11:39:36.636 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [%test%]
2023-08-13 11:39:36.636 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [dimension]
2023-08-13 11:39:36.636 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [notice]
2023-08-13 11:39:36.644 DEBUG 1592 --- [io-8080-exec-10] org.hibernate.SQL :
select
count(post0_.id) as col_0_0_
from
post post0_ cross
join
account account1_
where
post0_.author_id=account1_.id
and (
post0_.title like ? escape !
or post0_.content like ? escape !
or account1_.nickname like ? escape !
)
and post0_.board_category=?
and post0_.post_category=?
2023-08-13 11:39:36.645 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%test%]
2023-08-13 11:39:36.645 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CLOB] - [%test%]
2023-08-13 11:39:36.645 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [%test%]
2023-08-13 11:39:36.645 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [dimension]
2023-08-13 11:39:36.645 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [notice]
2023-08-13 11:39:36.650 DEBUG 1592 --- [io-8080-exec-10] org.hibernate.SQL :
select
count(notificati0_.id) as col_0_0_
from
notification notificati0_
where
notificati0_.account_id=?
and notificati0_.checked=?
2023-08-13 11:39:36.651 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [1]
2023-08-13 11:39:36.651 TRACE 1592 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [BOOLEAN] - [false]
2023-08-13 11:39:37.011 DEBUG 1592 --- [nio-8080-exec-8] org.hibernate.SQL :
select
post0_.id as col_0_0_,
post0_.view_count as col_1_0_,
post0_.like_count as col_2_0_,
post0_.comment_count as col_3_0_,
post0_.title as col_4_0_,
post0_.post_category as col_5_0_,
account1_.nickname as col_6_0_,
post0_.published_date_time as col_7_0_
from
post post0_
left outer join
account account1_
on post0_.author_id=account1_.id
where
(
post0_.title like ? escape !
or post0_.content like ? escape !
or account1_.nickname like ? escape !
)
and post0_.board_category=?
and post0_.post_category=?
order by
post0_.id desc limit ?
2023-08-13 11:39:37.011 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%test%]
2023-08-13 11:39:37.011 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CLOB] - [%test%]
2023-08-13 11:39:37.011 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [%test%]
2023-08-13 11:39:37.011 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [dimension]
2023-08-13 11:39:37.011 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [notice]
2023-08-13 11:39:37.015 DEBUG 1592 --- [nio-8080-exec-8] org.hibernate.SQL :
select
count(post0_.id) as col_0_0_
from
post post0_ cross
join
account account1_
where
post0_.author_id=account1_.id
and (
post0_.title like ? escape !
or post0_.content like ? escape !
or account1_.nickname like ? escape !
)
and post0_.board_category=?
and post0_.post_category=?
2023-08-13 11:39:37.015 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%test%]
2023-08-13 11:39:37.015 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CLOB] - [%test%]
2023-08-13 11:39:37.015 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [%test%]
2023-08-13 11:39:37.015 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [dimension]
2023-08-13 11:39:37.015 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [notice]
2023-08-13 11:39:37.020 DEBUG 1592 --- [nio-8080-exec-8] org.hibernate.SQL :
select
count(notificati0_.id) as col_0_0_
from
notification notificati0_
where
notificati0_.account_id=?
and notificati0_.checked=?
2023-08-13 11:39:37.020 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [1]
2023-08-13 11:39:37.020 TRACE 1592 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [BOOLEAN] - [false]