작성
·
322
0
countQuery관련해서 궁금한 것이 있습니다.
@Override
public Page<ReportChangeKRWDto> search(ReportSearchRequestDto dto, Pageable pageable) {
List<ReportChangeKRWDto> content = queryFactory
.select(new QReportChangeKRWDto(
reportChange.id.intValue(), //번호는 일단 임의로
reportChange.referenceDate,
reportChange.changeAmount,
reportChange.beforeAsset,
reportChange.changeRatio,
reportChange.afterAsset)
)
.where(searchType(dto))
.from(reportChange)
.orderBy(sortCondition(dto))
.offset(pageable.getOffset())
.limit(10) //TOP 10 고정
.fetch();
//countQuery 따로
JPAQuery<Long> countQuery = queryFactory
.select(reportChange.count())
.from(reportChange)
.where(searchType(dto))
.orderBy(sortCondition(dto));
// .offset(pageable.getOffset())
// .limit(10);
return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);
}
여기서 countQuery를 통해 최적화 하고 싶다면 countQuery부분에는 offset, limit을 빼고 쿼리?부분들만 적용해야 하는건가요 ??