Skip to content

[FIX] ACTIVE 전환 시 Redis 유저 플래그 제거 시점 수정 - #46

Merged
Jinyoung-Kim96 merged 2 commits into
devfrom
fix/43-npe
May 19, 2026
Merged

Jinyoung-Kim96 merged 2 commits into
devfrom
fix/43-npe

Conversation

@Jinyoung-Kim96

@Jinyoung-Kim96 Jinyoung-Kim96 commented May 19, 2026

Copy link
Copy Markdown
Contributor

📝 작업 내용

DB 유니크 제약 위반 발생하는 버그 수정

🚀 주요 변경 사항

완료한 이슈 번호 #45
Close #45
관련된 이슈 번호 (닫고 싶지 않은 경우)
Related to #

✅ 자체 체크리스트 (필수)

  • ./gradlew build 실행 결과 정상 (인증샷 첨부)
  • IntelliJ HTTP Client 테스트 완료 (인증샷 첨부)
  • 팀 내 컨벤션 준수 및 불필요한 로그, import 제거
  • 중요한 변경 사항이 팀에 공유되었는지

📸 테스트 인증샷

image

💬 리뷰어 전달사항 (선택)

특별히 봐주었으면 하는 부분이나 논의가 필요한 점을 적어주세요.

  • 논의점


📎 참고 자료

관련 문서, 레퍼런스 링크 등이 있다면 여기에 첨부해주세요.

Summary by CodeRabbit

릴리스 노트

  • 버그 수정

    • 대기열 순번 조회 실패 시 안정적인 정보 조회 로직 개선
    • 예약 완료 후 사용자가 대기열에 재등록 가능하도록 처리 개선
  • 성능 개선

    • 대기열 활성화 프로세스의 사용자 플래그 제거 타이밍 최적화로 시스템 안정성 향상

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Redis 순번 조회 실패 시 DB 재조회 처리를 enterWaiting에 추가하고, 사용자 플래그 제거 작업을 스케줄러(activateNextBatch)에서 완료 경로(completeWaiting)로 이동하여 중복 활성화로 인한 유니크 제약 위반 버그를 해결합니다.

Changes

대기열 활성화 흐름 개선

Layer / File(s) Summary
enterWaiting Redis 순번 조회 실패 처리
src/main/java/com/michelet/waiting/application/service/WaitingService.java
Redis 순번 조회(getPosition) 결과가 null일 때 DB에서 대기 엔티티를 재조회하여 순번 정보 없이 WaitingResult를 반환.
사용자 플래그 제거 타이밍 조정
src/main/java/com/michelet/waiting/application/service/WaitingService.java
completeWaiting에서 소프트 삭제 및 대기열 제거 후 waitingActivationPort.removeUser 호출 추가. activateNextBatch에서 ACTIVE 전환 후 수행되던 동일 호출 제거로 제거 타이밍을 완료 경로로 통합.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #41: WaitingActivationPort와 Redis 기반 대기 활성화 로직에 대한 이슈로, 본 PR의 Redis 순번 조회 및 사용자 플래그 제거 흐름 변경과 관련.

Possibly related PRs

  • Miche-Let/waiting-service#11: RedisWaitingActivationAdapter.getPosition이 ZSET에 없으면 null 반환 구현으로, 본 PR의 enterWaiting null 분기 처리와 직접 맞물림.
  • Miche-Let/waiting-service#42: WaitingActivationPortexistsUser/addUser/removeUser 메서드 추가 및 호출 타이밍 변경이 본 PR의 removeUser 흐름 재구성과 직접 연결.
  • Miche-Let/waiting-service#44: enterWaiting의 Redis position null 처리 로직 수정으로, 동일한 null 분기 처리 개선과 직접 연결.

Suggested reviewers

  • githyj-jang
  • ji-circle
  • Sehi55

Poem

🐰 Redis는 빠르지만 가끔 답장 안 해도,
DB로 다시 찾으면 모든 답장 있네요.
플래그 제거 시점을 옮겼으니,
중복 활성화는 이제 안녕! 👋
더 깨끗한 대기열로 점프! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 main change를 명확하게 설명하고 있으며, Redis 유저 플래그 제거 시점 수정이라는 핵심 변경사항을 정확하게 반영합니다.
Linked Issues check ✅ Passed PR의 코드 변경사항이 #45 이슈의 요구사항인 'ACTIVE 전환 시 unique constraint 위반 에러 해결'을 정확하게 구현했습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 #45 이슈의 범위 내에 있으며, WaitingService의 enterWaiting, completeWaiting, activateNextBatch 메서드의 Redis 플래그 제거 로직만 수정되었습니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/43-npe

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/com/michelet/waiting/application/service/WaitingService.java (1)

71-75: 💤 Low value

DB 재조회가 불필요하며, null position 발생 시 로깅 추가 권장

동일 트랜잭션 내에서 saved 엔티티가 이미 존재하므로 DB 재조회는 불필요합니다. 또한 Redis position이 null인 경우는 비정상적인 상황이므로, 디버깅을 위해 경고 로그를 추가하는 것이 좋습니다.

🔧 간소화 및 로깅 추가 제안
             if (position == null) {
-                Waiting updated = waitingRepository.findById(saved.getId())
-                        .orElseThrow(() -> new WaitingException(WaitingErrorCode.NOT_FOUND));
-                return WaitingResult.of(updated);
+                log.warn("[대기등록] Redis position 조회 실패 - restaurantId: {}, token: {}",
+                        command.restaurantId(), saved.getToken().value());
+                return WaitingResult.of(saved);
             }
🤖 Prompt for 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.

In `@src/main/java/com/michelet/waiting/application/service/WaitingService.java`
around lines 71 - 75, Remove the unnecessary DB re-query when position == null
inside WaitingService: instead of calling
waitingRepository.findById(saved.getId()) and throwing WaitingException, return
WaitingResult.of(saved) (use the already persisted saved entity) and add a
warning log entry that the Redis position was null (include identifying info
like saved.getId() and any user/context fields) so the abnormal null position is
recorded for debugging; keep the WaitingException only for true not-found
scenarios elsewhere.
🤖 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.

Nitpick comments:
In `@src/main/java/com/michelet/waiting/application/service/WaitingService.java`:
- Around line 71-75: Remove the unnecessary DB re-query when position == null
inside WaitingService: instead of calling
waitingRepository.findById(saved.getId()) and throwing WaitingException, return
WaitingResult.of(saved) (use the already persisted saved entity) and add a
warning log entry that the Redis position was null (include identifying info
like saved.getId() and any user/context fields) so the abnormal null position is
recorded for debugging; keep the WaitingException only for true not-found
scenarios elsewhere.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33d4cb35-1d70-40d2-8097-4637e858e0ff

📥 Commits

Reviewing files that changed from the base of the PR and between c66be87 and 7b4cc04.

📒 Files selected for processing (1)
  • src/main/java/com/michelet/waiting/application/service/WaitingService.java

@qldo qldo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인하였습니다

@Jinyoung-Kim96
Jinyoung-Kim96 merged commit 2334d9c into dev May 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ACTIVE 전환 시 Redis 유저 플래그 제거 시점 수정

2 participants