feat: 대기 등록 중복 체크 Redis 전환으로 성능 개선 - #42
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 Walkthrough개요대기 등록 중복 체크를 DB 쿼리 기반에서 Redis 기반으로 전환합니다. 포트 계약을 정의하고 Redis 어댑터로 구현한 후 서비스 플로우에 통합하며, 기존 DB 메서드를 제거합니다. 변경 사항Redis 기반 사용자 중복 체크
추정 코드 리뷰 노력🎯 2 (Simple) | ⏱️ ~10-15분 관련 PR
제안 리뷰어
시
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/com/michelet/waiting/application/port/WaitingActivationPort.java`:
- Around line 26-33: The current two-step contract (existsUser + addUser) in
WaitingActivationPort creates a TOCTOU race; replace or augment it with a single
atomic reservation method (e.g., reserveUser(UUID restaurantId, UUID userId):
boolean) on WaitingActivationPort that attempts an atomic check-and-set and
returns true if the user was reserved and false if already present, and keep
removeUser for cleanup; implement the adapter using Redis SETNX or a Lua script
with TTL to guarantee atomicity so concurrent requests cannot both succeed.
In `@src/main/java/com/michelet/waiting/application/service/WaitingService.java`:
- Around line 61-65: After enqueuing the token with
waitingActivationPort.add(command.restaurantId(), saved.getToken().value()), a
subsequent failure in waitingActivationPort.addUser(command.restaurantId(),
command.userId()) leaves the Redis queue token orphaned; update WaitingService
to handle this by performing compensation: wrap the addUser call in a try/catch
and on any exception call the corresponding removal method on
waitingActivationPort (e.g.,
waitingActivationPort.remove(command.restaurantId(), saved.getToken().value())
or the appropriate “delete token” API) to delete the queued token, then rethrow
or propagate the original error; alternatively, swap the order (addUser before
add) if semantically safe, but prefer the try/catch compensation to avoid
orphaned tokens.
- Around line 177-178: ACTIVE 저장 후
waitingActivationPort.removeUser(restaurantId, waiting.getUserId())에서 예외가 발생하면
잘못된 Redis 토큰 복구가 실행되는 문제입니다; WaitingService의 ACTIVE 저장/후속 작업 흐름을 변경해 ACTIVE 저장이
성공했는지 여부를 명시적으로 추적하고(예: boolean activatedSaved 변수) outer catch 블록에서 Redis 토큰 복구로
복원하는 분기를 activatedSaved == false일 때만 실행하도록 하거나, removeUser 호출을 별도의 try-catch로
감싸서 예외를 로깅만 하고 재던지지 않도록 처리해 removeUser 예외가 Redis 복구 로직을 트리거하지 않게 하세요 (참고 심볼:
waitingActivationPort.removeUser(...)와 현재의 catch 블록 내 Redis 토큰 복구 코드).
In
`@src/main/java/com/michelet/waiting/infrastructure/redis/RedisWaitingActivationAdapter.java`:
- Around line 41-43: The buildUserKey method lacks null checks for restaurantId
and userId unlike buildKey/buildSeqKey; update buildUserKey to validate both
inputs (e.g., throw IllegalArgumentException or NullPointerException consistent
with buildKey/buildSeqKey) and return the key only after validation so you never
produce a "null" segment that could pollute user flags—refer to buildKey and
buildSeqKey for the exact validation behavior and mirror that here.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ee566d0b-d3a4-4d40-9a0d-aa0c8f30fbcd
📒 Files selected for processing (5)
src/main/java/com/michelet/waiting/application/port/WaitingActivationPort.javasrc/main/java/com/michelet/waiting/application/service/WaitingService.javasrc/main/java/com/michelet/waiting/domain/repository/WaitingRepository.javasrc/main/java/com/michelet/waiting/infrastructure/persistence/jpa/WaitingRepositoryImpl.javasrc/main/java/com/michelet/waiting/infrastructure/redis/RedisWaitingActivationAdapter.java
💤 Files with no reviewable changes (1)
- src/main/java/com/michelet/waiting/domain/repository/WaitingRepository.java
📝 작업 내용
대기 등록 시 DB 조회가 병목현상이 일어나서 동시 80명 한계 발생,
대기열 서비스의 본연의 역할 ( 트래픽 폭발 시 예약 서비스 보호 )을 위해
중복 체크를 Redis로 전환하여 성능 개선 예상
🚀 주요 변경 사항
✅ 자체 체크리스트 (필수)
./gradlew build실행 결과 정상 (인증샷 첨부)📸 테스트 인증샷
💬 리뷰어 전달사항 (선택)
📎 참고 자료
Summary by CodeRabbit