Feat/#61 slot generator - #65
Merged
Merged
Conversation
- 충돌 해결 (병합) - 매일 새벽 4시 "오늘 + 30일" 날짜의 슬롯을 활성 매장에 생성 - 슬라이딩 윈도우 방식으로 항상 30일치 미래 슬롯 유지 - 이미 슬롯이 있는 매장/날짜는 스킵
…into feat/#61-slot-generator
…into feat/#61-slot-generator
- 기존: \"이미 그 날짜 슬롯이 1건이라도 있으면 스킵\" -> 부분 생성 시 나머지 누락 - 변경: 매장별 기대 슬롯과 실제 슬롯을 차집합으로 비교, 부족한 슬롯만 보충 - Repository에 findRemainTimesByStoreIdAndRemainDate 쿼리 추가 - buildSlotTimes 헬퍼 메서드로 슬롯 시간 생성 로직 분리
- 기존: 오늘+30일 단 하루치만 생성 -> 첫 실행 시 사이 날짜 비어있음 - 변경: 오늘 ~ 오늘+29일(총 30일) 범위를 매일 순회하며 보충 - 차집합 중복 방지 로직 덕분에 매일 돌아도 부담 없음
- 기존: \"이미 그 날짜 슬롯이 1건이라도 있으면 스킵\" -> 부분 생성 시 나머지 누락 - 변경: 매장별 기대 슬롯과 실제 슬롯을 차집합으로 비교, 부족한 슬롯만 보충 - Repository에 findRemainTimesByStoreIdAndRemainDate 쿼리 추가 - buildSlotTimes 헬퍼 메서드로 슬롯 시간 생성 로직 분리 - 파일 이름: StoreRemainService.java
- POST /api/v1/remains: Swagger 테스트용 수동 슬롯 생성 엔드포인트 - 스케줄러로 자동화되어 사용처가 없어졌으나 시딩/복구 시 부활 가능하도록 주석만 처리
- 매장 조회를 스케줄러 1회로 통합 (30일 루프 중복 제거) - 슬롯 차집합 N+1 쿼리 제거 (날짜별 일괄 조회 1회로 변경) - 매장 청크(500개) 단위 REQUIRES_NEW 트랜잭션 분리 (StoreRemainSlotWriter) - DateTimeFormatter 클래스 상수화 - generateMonthlyRemain에서 buildSlotTimes 재사용 - 미사용 메서드/변수 제거 (existsByStoreIdAndRemainDate, ReservationService.create 변수)
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces an automated scheduler to generate reservation slots for a 30-day window, replacing the previous manual endpoint. The implementation includes a chunking strategy and a dedicated transaction writer to handle large datasets. Review feedback highlights several areas for improvement: addressing potential memory issues when fetching existing slots for all stores at once, improving type safety by replacing generic Object[] results with DTOs or projections, optimizing performance by reducing redundant time parsing within loops, and removing dead code instead of leaving it commented out.
| * @return 슬롯이 보충된 매장 수 | ||
| */ | ||
| public int generateDailySlotsForStores(List<Store> stores, LocalDate targetDate) { | ||
| Map<Long, Set<LocalTime>> existingByStore = fetchExistingTimesByStore(targetDate); |
Contributor
There was a problem hiding this comment.
Comment on lines
+24
to
+33
| // 스케줄러 도입 후 사용 안 함. 기존 swagger 에서 수동으로 생성하던 POST /api/v1/remains 주석 처리. | ||
| // @PostMapping | ||
| // public ResponseEntity<ApiResponse<Void>> generateMonthlyRemain( | ||
| // @Valid @RequestBody StoreRemainCreateRequestDto request | ||
| // ) { | ||
| // storeRemainService.generateMonthlyRemain(request); | ||
| // return ResponseEntity | ||
| // .status(SuccessCode.REMAIN_CREATE_SUCCESS.getHttpStatus()) | ||
| // .body(ApiResponse.success(SuccessCode.REMAIN_CREATE_SUCCESS)); | ||
| // } |
Contributor
| ); | ||
|
|
||
| @Query("SELECT sr.store.id, sr.remainTime FROM StoreRemain sr WHERE sr.remainDate = :date") | ||
| List<Object[]> findStoreIdAndTimesByDate(@Param("date") LocalDate date); |
Contributor
Comment on lines
+169
to
+172
| LocalTime openTime = LocalTime.parse(store.getOpenTime(), TIME_FORMATTER); | ||
| LocalTime closeTime = LocalTime.parse(store.getCloseTime(), TIME_FORMATTER); | ||
|
|
||
| List<LocalTime> expectedTimes = buildSlotTimes(openTime, closeTime); |
Contributor
- 청크 단위로 기존 슬롯 조회하도록 변경하여 OOM 위험 제거 (메모리 ~95MB -> ~0.4MB) - Object[] 반환 대신 StoreRemainTimeView Projection으로 타입 안전성 확보 - StoreSlotPlan record로 매장 영업시간 파싱/슬롯 시간 계산을 1회로 단축 (파싱 호출 354만회 -> 11.8만회) - store_remain 테이블에 (remain_date, store_id), (store_id, remain_date) 복합 인덱스 추가
jaebeom79
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 기능 설명
필요시 실행결과 스크린샷 첨부
연결된 issue
연결된 issue를 자동을 닫기 위해 아래 {이슈넘버}를 입력해주세요.
close #{61}
✅ 체크리스트