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());