From 593248f46e8323f96c55ece52e8c95e7d8b0901b Mon Sep 17 00:00:00 2001 From: Arachneee Date: Thu, 26 Sep 2024 15:39:26 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B0=B0=EC=B9=98=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EC=A6=88=20=EC=A1=B0=EC=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haengdong/application/MemberService.java | 10 +++++----- .../haengdong/domain/bill/BillRepository.java | 14 ++------------ server/src/main/resources/application.yml | 1 + .../haengdong/application/MemberServiceTest.java | 6 ++++-- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/server/src/main/java/server/haengdong/application/MemberService.java b/server/src/main/java/server/haengdong/application/MemberService.java index fb3095eb3..e1af9d9ef 100644 --- a/server/src/main/java/server/haengdong/application/MemberService.java +++ b/server/src/main/java/server/haengdong/application/MemberService.java @@ -12,6 +12,7 @@ import server.haengdong.application.response.MemberAppResponse; import server.haengdong.application.response.MembersDepositAppResponse; import server.haengdong.application.response.MembersSaveAppResponse; +import server.haengdong.domain.bill.Bill; import server.haengdong.domain.bill.BillDetailRepository; import server.haengdong.domain.bill.BillRepository; import server.haengdong.domain.event.Event; @@ -67,11 +68,10 @@ private boolean isDuplicatedMemberNames(Set uniqueMemberNames, Event eve public List getCurrentMembers(String token) { Event event = getEvent(token); - List currentMembers = billRepository.findCurrentMembers(event); - if (currentMembers.isEmpty()) { - currentMembers = memberRepository.findAllByEvent(event); - } - return currentMembers.stream() + return billRepository.findFirstByEventOrderByIdDesc(event) + .map(Bill::getMembers) + .orElseGet(() -> memberRepository.findAllByEvent(event)) + .stream() .map(MemberAppResponse::of) .toList(); } diff --git a/server/src/main/java/server/haengdong/domain/bill/BillRepository.java b/server/src/main/java/server/haengdong/domain/bill/BillRepository.java index 632e349e7..23efe487c 100644 --- a/server/src/main/java/server/haengdong/domain/bill/BillRepository.java +++ b/server/src/main/java/server/haengdong/domain/bill/BillRepository.java @@ -1,11 +1,11 @@ package server.haengdong.domain.bill; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import server.haengdong.domain.event.Event; -import server.haengdong.domain.member.Member; @Repository public interface BillRepository extends JpaRepository { @@ -19,15 +19,5 @@ public interface BillRepository extends JpaRepository { """) List findAllByEvent(Event event); - @Query(""" - select bd.member - from BillDetail bd - where bd.bill = (select b - from Bill b - where b.event = :event - order by bd.bill.id desc - limit 1) - - """) - List findCurrentMembers(Event event); + Optional findFirstByEventOrderByIdDesc(Event event); } diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 2ae503547..22c337545 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -15,6 +15,7 @@ spring: ddl-auto: create properties: hibernate: + default_batch_fetch_size: 30 format_sql: true jdbc.time_zone: Asia/Seoul show-sql: true diff --git a/server/src/test/java/server/haengdong/application/MemberServiceTest.java b/server/src/test/java/server/haengdong/application/MemberServiceTest.java index 099326317..7b4e3feff 100644 --- a/server/src/test/java/server/haengdong/application/MemberServiceTest.java +++ b/server/src/test/java/server/haengdong/application/MemberServiceTest.java @@ -362,10 +362,12 @@ void getCurrentMembersTest() { Member member1 = MEMBER1; Member member2 = MEMBER2; Member member3 = MEMBER3; - Bill bill = Bill.create(event, "title", 100000L, List.of(member1, member2, member3)); + Bill bill1 = Bill.create(event, "title1", 100000L, List.of(member1)); + Bill bill2 = Bill.create(event, "title2", 200000L, List.of(member1, member2, member3)); + Bill bill3 = Bill.create(event, "title2", 200000L, List.of(member1, member2, member3)); eventRepository.save(event); memberRepository.saveAll(List.of(member1, member2, member3)); - billRepository.save(bill); + billRepository.saveAll(List.of(bill1, bill2, bill3)); List currentMembers = memberService.getCurrentMembers(event.getToken());