diff --git a/batch/batch-booking/src/main/java/com/pgms/batchbooking/seat/SeatReleaseTasklet.java b/batch/batch-booking/src/main/java/com/pgms/batchbooking/seat/SeatReleaseTasklet.java index 9ddb97ff..705509a0 100644 --- a/batch/batch-booking/src/main/java/com/pgms/batchbooking/seat/SeatReleaseTasklet.java +++ b/batch/batch-booking/src/main/java/com/pgms/batchbooking/seat/SeatReleaseTasklet.java @@ -25,7 +25,7 @@ public class SeatReleaseTasklet implements Tasklet{ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { List tickets = ticketRepository.findAll(LocalDateTime.now(), BookingStatus.WAITING_FOR_PAYMENT); - tickets.forEach(ticket -> ticket.getSeat().updateStatus(EventSeatStatus.AVAILABLE)); + ticketRepository.updateSeatStatusBulk(EventSeatStatus.AVAILABLE, tickets.stream().map(Ticket::getId).toList()); return RepeatStatus.FINISHED; } } diff --git a/core/core-domain/src/main/java/com/pgms/coredomain/domain/booking/repository/TicketRepository.java b/core/core-domain/src/main/java/com/pgms/coredomain/domain/booking/repository/TicketRepository.java index e6af011e..09def07b 100644 --- a/core/core-domain/src/main/java/com/pgms/coredomain/domain/booking/repository/TicketRepository.java +++ b/core/core-domain/src/main/java/com/pgms/coredomain/domain/booking/repository/TicketRepository.java @@ -4,11 +4,13 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import com.pgms.coredomain.domain.booking.BookingStatus; import com.pgms.coredomain.domain.booking.Ticket; +import com.pgms.coredomain.domain.event.EventSeatStatus; public interface TicketRepository extends JpaRepository { @@ -23,4 +25,8 @@ public interface TicketRepository extends JpaRepository { + "AND b.status = :bookingStatus ") List findAll(@Param("datetime") LocalDateTime dateTime, @Param("bookingStatus") BookingStatus bookingStatus); + + @Modifying + @Query("UPDATE Ticket t SET t.seat.status = :status WHERE t IN :ticketIds") + void updateSeatStatusBulk(@Param("status") EventSeatStatus status, @Param("ticketIds") List ticketIds); }