From 136eb12b8495a9409bb6d8dc3915b914d13adb0e Mon Sep 17 00:00:00 2001 From: Dayeon-Hong Date: Tue, 28 May 2024 16:22:52 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20Fetch=20Join=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20n+1=EC=9D=B4=EC=8A=88=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #40 --- .../domain/schedule/repository/ScheduleRepository.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java b/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java index 5891e71f..b322c3b5 100644 --- a/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java +++ b/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java @@ -12,8 +12,10 @@ public interface ScheduleRepository extends JpaRepository { Optional findByIdAndActivatedIsTrue(Long scheduleId); - @Query("SELECT s FROM Schedule s WHERE s.member = :member AND s.activated = true ORDER BY s.updatedAt DESC") + @Query("SELECT s FROM Schedule s LEFT JOIN FETCH s.country WHERE s.member = :member AND s.activated = true ORDER BY s.updatedAt DESC") List findSchedulesByMember(@Param("member") Member member); - List findTop5ByMemberOrderByIdDesc(Member member); + @Query("SELECT s FROM Schedule s LEFT JOIN FETCH s.scheduleDetails WHERE s.member = :member ORDER BY s.id DESC") + List findTop5ByMemberOrderByIdDescWithDetails(@Param("member") Member member); + }