Skip to content

Commit

Permalink
Merge pull request #835 from woowacourse-teams/refactor/#833
Browse files Browse the repository at this point in the history
인기순 전체 게시글 목록 조회 기능의 성능 개선을 위한 QueryDsl 코드 수정
  • Loading branch information
tjdtls690 authored Nov 7, 2023
2 parents 1d3a5e1 + 8d08f39 commit f1dc85b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public List<Post> findPostsWithFilteringAndPaging(
final Long categoryId,
final Pageable pageable
) {
return jpaQueryFactory
.selectDistinct(post)
List<Long> postIds = jpaQueryFactory
.select(post.id)
.from(post)
.join(post.writer).fetchJoin()
.leftJoin(post.postCategories, postCategory)
.where(
categoryIdEq(categoryId),
Expand All @@ -65,6 +64,14 @@ public List<Post> findPostsWithFilteringAndPaging(
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

return jpaQueryFactory
.selectDistinct(post)
.from(post)
.join(post.writer).fetchJoin()
.where(post.id.in(postIds))
.orderBy(orderBy(postSortType))
.fetch();
}

private BooleanExpression categoryIdEq(final Long categoryId) {
Expand Down

0 comments on commit f1dc85b

Please sign in to comment.