Skip to content

Commit efaabf9

Browse files
committed
#107 [FIX] 이미지 관련 쿼리 수정
1 parent 35a8bf4 commit efaabf9

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/main/java/com/example/trace/post/repository/PostRepositoryCustomImpl.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ private BooleanExpression postTypeEq(PostType postType) {
4141
}
4242

4343
StringExpression imageUrlExpr = Expressions.cases()
44-
.when(post.images.isEmpty())
45-
.then("")
44+
.when(post.images.isEmpty()).then("")
4645
.otherwise(
4746
JPAExpressions
4847
.select(postImage.imageUrl)
4948
.from(postImage)
50-
.where(postImage.post.eq(post))
51-
.orderBy(postImage.id.asc())
52-
.limit(1)
49+
.where(
50+
postImage.post.eq(post)
51+
.and(postImage.id.eq(
52+
JPAExpressions
53+
.select(postImage.id.min())
54+
.from(postImage)
55+
.where(postImage.post.eq(post))
56+
))
57+
)
5358
);
5459
Expression<Long> totalEmotionCount = JPAExpressions
5560
.select(emotion.count())
@@ -142,7 +147,7 @@ public List<PostFeedDto> findPostsWithCursor(
142147
post.user.providerId,
143148
post.user.nickname,
144149
post.user.profileImageUrl,
145-
imageUrlExpr, // 서브쿼리 사용
150+
imageUrlExpr,
146151
post.viewCount,
147152
post.commentList.size().longValue(),
148153
post.createdAt,
@@ -154,10 +159,9 @@ public List<PostFeedDto> findPostsWithCursor(
154159
.from(post)
155160
.leftJoin(post.user)
156161
.leftJoin(post.verification) // verification 조인 추가
157-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
158162
.where(
159163
postTypeEq(postType),
160-
postCursorCondition(cursorDateTime, cursorId) // 커서 조건
164+
postCursorCondition(cursorDateTime, cursorId)
161165
)
162166
.orderBy(post.createdAt.desc(), post.id.desc())
163167
.limit(size + 1)
@@ -198,7 +202,6 @@ public List<PostFeedDto> findPostsWithCursorAndSearch(
198202
.from(post)
199203
.leftJoin(post.user)
200204
.leftJoin(post.verification)
201-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
202205
.where(
203206
postTypeEq(postType),
204207
postCursorCondition(cursorDateTime, cursorId),
@@ -305,7 +308,6 @@ public List<PostFeedDto> findUserPosts(
305308
.from(post)
306309
.leftJoin(post.user)
307310
.leftJoin(post.verification)
308-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
309311
.where(
310312
post.user.providerId.eq(providerId),
311313
postCursorCondition(cursorDateTime, cursorId)
@@ -348,7 +350,6 @@ public List<PostFeedDto> findUserCommentedPosts(
348350
.from(post)
349351
.leftJoin(post.user)
350352
.leftJoin(post.verification)
351-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
352353
.where(
353354
post.id.in(
354355
JPAExpressions
@@ -399,7 +400,6 @@ public List<PostFeedDto> findUserEmotedPosts(
399400
.from(post)
400401
.leftJoin(post.user)
401402
.leftJoin(post.verification)
402-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
403403
.where(
404404
post.id.in(
405405
JPAExpressions

0 commit comments

Comments
 (0)