[Refactor] SLO에 영향을 미치는 쿼리 개선 작업 Prod 적용#209
Conversation
- EntityGraph에서 Batchsize 조절로 쿼리 로직 변경
- EntityGraph에서 Batchsize 조절로 쿼리 로직 변경
- EntityGraph에서 Batchsize 조절로 쿼리 로직 변경
[Refactor] SLO에 영향을 미치는 쿼리 개선 작업
Walkthrough리포지토리 전반에서 목록 반환 타입을 List에서 Page로 변경하고 @entitygraph를 제거했습니다. Cheer 엔티티에 @Embedded CheerTags 필드를 추가했습니다. 서비스와 테스트는 페이지네이션에 맞게 수정되었습니다. dev/prod 환경에 Hibernate default_batch_fetch_size=30을 설정했습니다. Terraform WAF 규칙이 헤더 기반 문자열 매칭으로 재구성되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant S as CheerService
participant R as CheerRepository
participant DB as Database
C->>S: getCheers(filters, page, size)
S->>R: findAllByConditions(filters, Pageable)
R->>DB: SELECT ... WHERE ... ORDER BY created_at DESC LIMIT/OFFSET
DB-->>R: Page<Cheer> (content + metadata)
R-->>S: Page<Cheer>
S->>S: map page.getContent() to DTOs
S-->>C: CheerListResponse (items, page info)
note over S, C: 변경사항: List → Page 기반 흐름
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📄 Terraform Plan Summary🛡️ Common InfrastructureStatus: ✅ No Changes 🚀 Production EnvironmentStatus: ✅ No Changes 📋 Full Results: View in Actions |
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/main/java/eatda/domain/cheer/Cheer.java(1 hunks)src/main/java/eatda/domain/store/Store.java(1 hunks)src/main/java/eatda/repository/cheer/CheerRepository.java(3 hunks)src/main/java/eatda/repository/store/StoreRepository.java(3 hunks)src/main/java/eatda/repository/story/StoryRepository.java(0 hunks)src/main/java/eatda/service/cheer/CheerService.java(3 hunks)src/main/java/eatda/service/store/StoreService.java(2 hunks)src/main/resources/application-dev.yml(1 hunks)src/main/resources/application-local.yml(1 hunks)src/main/resources/application-prod.yml(1 hunks)src/test/java/eatda/repository/cheer/CheerRepositoryTest.java(6 hunks)src/test/java/eatda/repository/store/StoreRepositoryTest.java(6 hunks)terraform/common/waf/main.tf(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/eatda/repository/story/StoryRepository.java
🧰 Additional context used
🪛 GitHub Actions: Notify Discord on `/noti` Comment
src/main/java/eatda/domain/cheer/Cheer.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/resources/application-dev.yml
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/resources/application-local.yml
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/java/eatda/service/store/StoreService.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/test/java/eatda/repository/cheer/CheerRepositoryTest.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
terraform/common/waf/main.tf
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/test/java/eatda/repository/store/StoreRepositoryTest.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/resources/application-prod.yml
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/java/eatda/domain/store/Store.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/java/eatda/service/cheer/CheerService.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/java/eatda/repository/store/StoreRepository.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
src/main/java/eatda/repository/cheer/CheerRepository.java
[error] 1-1: No such file or directory. The CI script attempted to process this path but it does not exist in the repository.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
🔇 Additional comments (13)
src/main/resources/application-local.yml (1)
25-25: 명확한 주석 추가 감사합니다.Local 환경에서 batch size를 제외한 이유가 바로 이해됩니다.
src/main/resources/application-dev.yml (1)
30-32: 동일한 배치 페치 크기 적용 확인 완료
dev 환경에서도default_batch_fetch_size: 30을 맞춰 주어 prod와 일관성이 확보되었습니다. 추가 수정 없이 이대로 적용해도 무방해 보입니다.src/main/java/eatda/domain/store/Store.java (1)
60-65: LGTM! 배치 페칭 전략에 대한 명확한 문서화현재 데이터 규모와 향후 성능 모니터링 필요성을 명확히 문서화했습니다. 배치 크기 설정에 대한 근거와 향후 검토 시점을 잘 설명하고 있습니다.
src/test/java/eatda/repository/store/StoreRepositoryTest.java (1)
17-17: LGTM! 페이지네이션 API 변경에 맞춘 테스트 업데이트Repository가
Page<Store>를 반환하도록 변경됨에 따라 테스트도 올바르게 업데이트되었습니다.Page는Stream을 지원하므로 기존 assertion 로직이 그대로 작동합니다.Also applies to: 65-69, 91-95, 104-108, 138-142, 161-164
src/main/java/eatda/service/store/StoreService.java (2)
22-22: LGTM! Repository의 페이지네이션 변경 사항 반영
Page<Store>를 사용하도록 올바르게 변경되었으며, 스트리밍 로직도 정상적으로 작동합니다.Also applies to: 49-59
46-46: TODO 주석 추적 권장N+1 문제 해결에 대한 TODO가 남아있습니다. 현재 PR에서 부분적으로 개선되었지만, 추가 작업이 필요할 수 있습니다.
이 TODO를 별도 이슈로 추적하여 향후 개선 작업을 관리하시겠습니까?
src/test/java/eatda/repository/cheer/CheerRepositoryTest.java (1)
16-16: LGTM! Repository API 변경에 맞춘 테스트 업데이트
CheerRepository가Page<Cheer>를 반환하도록 변경됨에 따라 모든 테스트가 올바르게 업데이트되었습니다.Also applies to: 68-72, 94-99, 114-119, 149-154, 173-177
src/main/java/eatda/domain/cheer/Cheer.java (1)
52-59: LGTM! 성능 트레이드오프를 명확히 문서화한 설계 결정
@Embedded CheerTags도입과 함께 배치 페칭 제약사항을 명확히 문서화했습니다. 현재 데이터 규모에서는 적절하며, 향후 필요시@OneToMany로 재설계할 수 있음을 명시했습니다.Also applies to: 69-69
src/main/java/eatda/service/cheer/CheerService.java (1)
28-28: LGTM! 페이지네이션을 올바르게 처리Repository의
Page<Cheer>반환을 적절히 처리하고 있습니다.getContent()를 통해 실제 데이터를 추출하여 응답 객체로 변환하는 로직이 올바릅니다.Also applies to: 119-129, 147-153
src/main/java/eatda/repository/store/StoreRepository.java (2)
11-11: LGTM! 페이지네이션 지원을 위한 API 변경
List<Store>에서Page<Store>로의 변경이 올바르게 적용되었습니다. 이는 대용량 데이터 조회 시 메모리 효율성과 성능을 개선합니다.Also applies to: 36-44
54-59: query null-check 패턴 일관성 확인
CheerRepository(38–40)와 StoreRepository(55–57) 모두if (query != null) query.distinct(true);패턴이 적용되어 있어, count 쿼리 생성 시 query가 null일 수 있는 상황을 대비한 방어 로직이 코드베이스 전반에 일관되게 적용된 것을 확인했습니다.src/main/java/eatda/repository/cheer/CheerRepository.java (2)
11-11: LGTM! 페이지네이션 API로의 일관된 마이그레이션
StoreRepository와 동일한 패턴으로Page<Cheer>반환 타입을 적용했습니다. 이는 전체 리포지토리 레이어에서 일관된 페이지네이션 전략을 제공합니다.Also applies to: 20-27, 51-51
38-40: LGTM! StoreRepository와 동일한 방어 패턴 적용
StoreRepository와 동일하게 count 쿼리 생성 시 query null 상황을 대비한 방어 코드를 적용했습니다. 일관성 있는 구현입니다.
leegwichan
left a comment
There was a problem hiding this comment.
고생하셨습니다! 쿼리 개선 상황 파악되셨다면 머지해도 좋을 것 같습니다!
|
🎉 This PR is included in version 1.9.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |



✨ 개요
레이턴시 개선, 1 + N 쿼리 문제가 발생하지 않는것을 확인했습니다.
🧾 관련 이슈
#205
🔍 참고 사항 (선택)
Summary by CodeRabbit