[Refactor] ConstraintViolationException 파싱 로직 유틸로 통합#176
Conversation
3곳에 중복된 예외 체인 탐색 로직을 ConstraintViolationUtils.isViolation()으로 추출. 버그 수정 시 한 곳만 고치면 되고, 제약 조건 이름 변경에도 누락 없이 대응 가능. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 본 PR은 데이터베이스 제약 조건 위반 예외를 처리하는 중복 로직을 통합하여 유지보수성을 높이고 버그 발생 가능성을 줄이는 것을 목적으로 합니다. 각 서비스에서 개별적으로 구현되어 있던 예외 파싱 로직을 공통 유틸리티 클래스로 추상화하였으며, 이를 통해 향후 유사한 예외 처리 시 일관된 방식을 적용할 수 있게 되었습니다. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request centralizes database unique constraint violation checks by introducing a shared ConstraintViolationUtils utility class and its corresponding tests, replacing duplicate local helper methods across several services. The review feedback suggests a performance improvement to cache the compiled regular expression patterns in a ConcurrentHashMap to avoid redundant compilation on every method call.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| public final class ConstraintViolationUtils { | ||
|
|
||
| private ConstraintViolationUtils() {} | ||
|
|
||
| public static boolean isViolation(Throwable exception, String constraintName) { | ||
| Pattern constraintNamePattern = Pattern.compile( | ||
| "(?<![A-Za-z0-9_])" + Pattern.quote(constraintName) + "(?![A-Za-z0-9_])" | ||
| ); |
There was a problem hiding this comment.
[P3] 정규식 패턴 매번 컴파일하는 성능 비효율 개선
isViolation 메서드가 호출될 때마다 Pattern.compile을 사용하여 정규식 패턴을 매번 새로 생성하고 있습니다. 예외 처리 흐름이라 하더라도, 동시 요청이 많거나 예외가 빈번히 발생하는 상황에서는 CPU 자원을 불필요하게 소모할 수 있습니다.
제약 조건 이름(constraintName)별로 컴파일된 Pattern 객체를 캐싱하여 재사용하도록 개선하는 것을 권장합니다. ConcurrentHashMap을 사용해 간단히 캐싱할 수 있습니다.
public final class ConstraintViolationUtils {
private static final java.util.Map<String, Pattern> PATTERN_CACHE = new java.util.concurrent.ConcurrentHashMap<>();
private ConstraintViolationUtils() {}
public static boolean isViolation(Throwable exception, String constraintName) {
Pattern constraintNamePattern = PATTERN_CACHE.computeIfAbsent(constraintName, name ->
Pattern.compile("(?<![A-Za-z0-9_])" + Pattern.quote(name) + "(?![A-Za-z0-9_])")
);References
- 우선순위 규칙에 따라 성능(Performance) 관련 개선 사항을 제안합니다. 정규식 패턴을 매번 컴파일하는 비효율을 캐싱을 통해 해결합니다. (link)
🧾 요약
🔗 이슈
✨ 변경 내용
ConstraintViolationUtils.isViolation()유틸 클래스 추가 (common/exception)TrackingSessionService.isActiveSessionUniqueViolation()제거 후 유틸로 교체HikingRecordService.isDifficultyFeedbackHikingRecordUniqueViolation()제거 후 유틸로 교체UserBlockService.isUniqueViolation()제거 후 유틸로 교체✅ 확인