Skip to content

Commit

Permalink
Refactor :: Notification 조회 로직 변경 #346
Browse files Browse the repository at this point in the history
기존 쿼리를 두 단계로 나눠서 N+1 문제를 변경함
기존 쿼리에선 N+1 이 발생해 조회를 여러번 했는데 이를 2번 쿼리를 나누어 날려 빈도수를 줄이고 속도 개선을 함
  • Loading branch information
yeseong0412 committed Nov 26, 2024
1 parent 132e5bc commit 8d89f1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class NotificationEntity(
var content: String,

@ElementCollection
@Column(nullable = false)
val emoji: MutableList<NotificationEmoji> = mutableListOf(),

@Column(nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class NotificationRepositoryCustomImpl(
override fun findByWorkspaceId(workspaceId: String, pageable: Pageable): List<NotificationEntity> {
val notice: QNotificationEntity = QNotificationEntity.notificationEntity

return jpaQueryFactory
.select(notice)
val noticeIdList = jpaQueryFactory
.select(notice.id)
.from(notice)
.where(
notice.workspaceId.eq(workspaceId),
Expand All @@ -24,6 +24,15 @@ class NotificationRepositoryCustomImpl(
.offset(pageable.offset)
.limit(pageable.pageSize.toLong())
.fetch().orEmpty().toList()

return jpaQueryFactory
.select(notice)
.from(notice)
.leftJoin(notice.user).fetchJoin()
.leftJoin(notice.emoji).fetchJoin()
.where(notice.id.`in`(noticeIdList))
.fetch().orEmpty().toList()

}

}

0 comments on commit 8d89f1f

Please sign in to comment.