fix: 광고 랜덤 조회의 반복 단건 조회를 제거해 쿼리 횟수를 줄임 - #449
Conversation
📝 Walkthrough개요저장소 메서드 변경사항
예상 코드 리뷰 노력🎯 2 (Simple) | ⏱️ ~12 분 관련 가능 PR
시
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/gg/agit/konect/domain/advertisement/service/AdvertisementService.java`:
- Around line 28-51: The getRandomAdvertisements method can throw
IndexOutOfBounds when count is negative; at the start of
AdvertisementService.getRandomAdvertisements validate or clamp count to
non-negative (e.g., if count <= 0 return AdvertisementsResponse.from(List.of())
or set count = Math.max(0, count)) so the subsequent
visibleAdvertisements.size() >= count check and subList(0, count) cannot receive
a negative value; update references to count accordingly before creating
selectedAdvertisements.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 11c02f0f-b6c3-42cb-ad81-34ef90e29dbc
📒 Files selected for processing (2)
src/main/java/gg/agit/konect/domain/advertisement/repository/AdvertisementRepository.javasrc/main/java/gg/agit/konect/domain/advertisement/service/AdvertisementService.java
💤 Files with no reviewable changes (1)
- src/main/java/gg/agit/konect/domain/advertisement/repository/AdvertisementRepository.java
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/**/*.java
⚙️ CodeRabbit configuration file
src/main/java/**/*.java: 아래 원칙으로 리뷰 코멘트를 작성한다.
- 코멘트는 반드시 한국어로 작성한다.
- 반드시 수정이 필요한 항목만 코멘트로 남기고, 단순 취향 차이는 지적하지 않는다.
- 각 코멘트 첫 줄에 심각도를
[LEVEL: high|medium|low]형식으로 반드시 표기한다.- 심각도 기준: high=운영 장애 가능, medium=품질 저하, low=개선 권고.
- 각 코멘트는 "문제 -> 영향 -> 제안" 순서로 3문장 이내로 간결하게 작성한다.
- 가능하면 재현 조건 및 실패 시나리오도 포함한다.
- 제안은 현재 코드베이스(Spring Boot + JPA + Flyway) 패턴과 일치해야 한다.
- 보안, 트랜잭션 경계, 예외 처리, N+1, 성능 회귀 가능성을 우선 점검한다.
- 가독성: 변수/메서드 이름이 의도를 바로 드러내는지, 중첩과 메서드 길이가 과도하지 않은지 점검한다.
- 단순화: 불필요한 추상화, 중복 로직, 과한 방어 코드가 있으면 더 단순한 대안을 제시한다.
- 확장성: 새 요구사항 추가 시 변경 범위가 최소화되는 구조인지(하드코딩 분기/값 여부 포함) 점검한다.
Files:
src/main/java/gg/agit/konect/domain/advertisement/service/AdvertisementService.java
**/*
⚙️ CodeRabbit configuration file
**/*: 공통 리뷰 톤 가이드:
- 모든 코멘트는 첫 줄에
[LEVEL: ...]태그를 포함한다.- 과장된 표현 없이 사실 기반으로 작성한다.
- 한 코멘트에는 하나의 이슈만 다룬다.
- 코드 예시가 필요하면 최소 수정 예시를 제시한다.
- 가독성/단순화/확장성 이슈를 발견하면 우선순위를 높여 코멘트한다.
Files:
src/main/java/gg/agit/konect/domain/advertisement/service/AdvertisementService.java
🔇 Additional comments (1)
src/main/java/gg/agit/konect/domain/advertisement/service/AdvertisementService.java (1)
29-30: N+1 쿼리 문제 해결 확인.기존 ID 목록 조회 후 반복 단건 조회하던 로직을 제거하고, 최초 조회한 광고 목록을 직접 재활용하여 쿼리 횟수를
1 + N에서1로 줄였습니다.ThreadLocalRandom사용과 shuffle 전 방어적 복사도 적절합니다.Also applies to: 36-50
🔍 개요
1 + N번쿼리가 나가게 된다.🚀 주요 변경 내용
💬 참고 사항
✅ Checklist (완료 조건)