From 161cd4a30018dc53f57b1ff6c7afe8651776c90e Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sun, 27 Oct 2024 20:18:46 +0900 Subject: [PATCH] =?UTF-8?q?#547=20[feat]=20n+1=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mile/curious/repository/CuriousRepositoryCustomImpl.java | 2 ++ .../com/mile/moim/repository/MoimPopularInfoRepository.java | 1 - .../main/java/com/mile/moim/repository/MoimRepository.java | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/module-domain/src/main/java/com/mile/curious/repository/CuriousRepositoryCustomImpl.java b/module-domain/src/main/java/com/mile/curious/repository/CuriousRepositoryCustomImpl.java index 5e832f33..ac12ef84 100644 --- a/module-domain/src/main/java/com/mile/curious/repository/CuriousRepositoryCustomImpl.java +++ b/module-domain/src/main/java/com/mile/curious/repository/CuriousRepositoryCustomImpl.java @@ -28,6 +28,7 @@ public List findMostCuriousPostBeforeOneWeek(fina .join(curious.post, post) .join(topic).on(post.topic.id.eq(topic.id)) .join(moim).on(topic.moim.id.eq(moim.id)) + .join(post.writerName).fetchJoin() .where(moim.id.eq(targetMoim.getId())) .where(curious.createdAt.between(now.minusDays(WEEK), now)) .groupBy(post.id) @@ -41,6 +42,7 @@ public List findPostByLatestCurious(final Moim targetMoim, final int reque .join(curious.post, post) .join(topic).on(post.topic.id.eq(topic.id)) .join(moim).on(topic.moim.id.eq(moim.id)) + .join(post.writerName).fetchJoin() .where(moim.id.eq(targetMoim.getId())) .where(post.notIn(posts)) .orderBy(curious.createdAt.desc()) diff --git a/module-domain/src/main/java/com/mile/moim/repository/MoimPopularInfoRepository.java b/module-domain/src/main/java/com/mile/moim/repository/MoimPopularInfoRepository.java index 5de7304c..b3da005d 100644 --- a/module-domain/src/main/java/com/mile/moim/repository/MoimPopularInfoRepository.java +++ b/module-domain/src/main/java/com/mile/moim/repository/MoimPopularInfoRepository.java @@ -2,7 +2,6 @@ import com.mile.moim.domain.popular.MoimPopularInfo; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.Repository; import org.springframework.scheduling.annotation.Scheduled; import java.util.Optional; diff --git a/module-domain/src/main/java/com/mile/moim/repository/MoimRepository.java b/module-domain/src/main/java/com/mile/moim/repository/MoimRepository.java index 3bf9c66a..43865d32 100644 --- a/module-domain/src/main/java/com/mile/moim/repository/MoimRepository.java +++ b/module-domain/src/main/java/com/mile/moim/repository/MoimRepository.java @@ -13,6 +13,10 @@ import java.util.Optional; public interface MoimRepository extends JpaRepository { + + @Query("select m from Moim m join fetch m.owner where m.id = :id") + Optional findById(final long id); + Boolean existsByNormalizedName(final String normalizedName); @Query("SELECT m FROM Post p JOIN p.topic t JOIN t.moim m WHERE m.isPublic = true AND p.isTemporary = false AND p.createdAt BETWEEN :startOfWeek AND :endOfWeek GROUP BY m ORDER BY COUNT(p)")