-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 솝탬프 박수 기능 구현 - #625 #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…p_count, version 동시 증가)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다~ 👍 👍
메서드를 이렇게 주석으로 관리하면 인수인계 시에도 좋을 것 같아요 👍
| private Clap createClapSafely(Long userId, Long stampId) { | ||
| try { | ||
| Clap fresh = Clap.builder() | ||
| .userId(userId) | ||
| .stampId(stampId) | ||
| .clapCount(0) | ||
| .build(); | ||
| return clapRepository.saveAndFlush(fresh); | ||
| } catch (DataIntegrityViolationException e) { | ||
| return clapRepository.findByUserIdAndStampId(userId, stampId) | ||
| .orElseThrow(() -> e); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 생성하는 경우에 clapCount까지 한번에 반영하지 않고 insert, update 를 진행하도록 하신 이유가 있을까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
새 Clap 행을 만들 때 바로 clapCount를 더하면
생성 시점 경합이나 상한 계산이 SQL 단으로 분산돼 정합성 관리가 어려워져서
항상 0으로 초기화 후, 증가 로직을 단일 경로(incrementClapCount())로 통일하고자 했습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 !
| int appliedCount = soptampFacade.addClap(userId, stampId, request.getClapCount()); | ||
| int totalClapCount = soptampFacade.getStampClapCount(stampId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
읽기, 쓰기 연산도 파사드로 분리 호출돼서 잘 설계해주신거같아요 👍🏻
| @ExtendWith(MockitoExtension.class) | ||
| class ClapServiceTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 코드까지 작성해주셨네요
좋습니다 🚀
Related issue 🛠
Work Description ✏️
동시성/락 설계 의사결정 배경
추가로, (stamp_id, user_id) 유니크 제약으로 최초 생성 경합은 DB가 보장하고, 충돌 시 재조회로 해결.
=> 결론: Clap은 낙관적 락 + 재시도가 성능·단순성·정합성을 동시에 만족.
=> 결론: Stamp 총합은 **네이티브 원자 증가(RETURNING)**가 고경합 시나리오에서 가장 안정적·효율적.
Trouble Shooting ⚽️
Related ScreenShot 📷
Uncompleted Tasks 😅
To Reviewers 📢