Skip to content

Commit

Permalink
fix: 게시글 조회 쿼리 innerJoin, fetchJoin 으로 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
enjay27 committed Jun 11, 2021
1 parent 16632f2 commit b202156
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.devin.dev.dto.post.*;
import com.devin.dev.entity.post.*;
import com.devin.dev.entity.reply.QReply;
import com.devin.dev.entity.reply.QReplyImage;
import com.devin.dev.entity.reply.QReplyLike;
import com.devin.dev.entity.user.User;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.OrderSpecifier;
Expand All @@ -23,9 +25,12 @@

import static com.devin.dev.entity.post.QPost.post;
import static com.devin.dev.entity.post.QPostImage.postImage;
import static com.devin.dev.entity.post.QPostLike.postLike;
import static com.devin.dev.entity.post.QPostTag.postTag;
import static com.devin.dev.entity.post.QSubject.subject;
import static com.devin.dev.entity.reply.QReply.reply;
import static com.devin.dev.entity.reply.QReplyImage.replyImage;
import static com.devin.dev.entity.reply.QReplyLike.replyLike;
import static com.devin.dev.entity.user.QUser.user;
import static org.springframework.util.StringUtils.hasText;

Expand Down Expand Up @@ -120,7 +125,9 @@ public Optional<PostDetailsDto> findPostDetailsById(Long id, ReplyOrderCondition
Post result = queryFactory
.select(post)
.from(post)
.leftJoin(post.replies, reply).fetchJoin()
.innerJoin(post.replies, reply).fetchJoin()
.innerJoin(post.user, user).fetchJoin()
.innerJoin(reply.user, user).fetchJoin()
.where(post.id.eq(id))
.orderBy(
replyOrder(condition)
Expand Down

0 comments on commit b202156

Please sign in to comment.