Merged
Conversation
hisonghy
approved these changes
May 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🌱 관련 이슈
📌 작업 내용 및 특이사항
🔍 참고사항
user id와 post id로 먼저 bookmark 존재하는지 확인 -> 있으면 OK 반환
북마크 존재하지 않으면 새롭게 생성 -> CREATED 반환
북마크 존재하는지 확인한 시점부터 생성 과정 사이에 동일한 북마크가 생성되어 중복 생성되는 것을 막고자 Bookmark 내의 user id와 post id 쌍의 unique 제약 조건 추가
북마크 insert 시 (user_id,post_id)가 같은 것이 있으면 insert나 update 하지 않고 ok 바로 반환 (postgresql ON CONFLICT 활용)
: SQL 쿼리 -> INSERT INTO bookmark (user_id, post_id) VALUES (userId, postId) ON CONFLICT (user_id, post_id) DO NOTHING;
만약 두 쓰레드가 동시에 해당 sql 쿼리문을 요청했고, conflict 확인이 되지 않아서 (user_id,post_id)가 같은 동일한 북마크 생성 요청이 갈 경우, 두번째 요청에서 unique key 제약조건 위반 예외 발생 -> 예외 그대로 반환하지 않고 무시하여 OK 반환
두 개의 thread, 두개의 transaction에서 쿼리문이 완전히 동일한 시점에 나가서 문제가 생기는 경우를 방지하려면 transcation 격리 수준을 높게 설정할 수도 있지만, 실질적으로 북마크 생성 요청에서 그런 수준의 격리 까지는 필요 없을 것으로 판단
postgresql 기본 트랜잭션 격리 수준인 READ_COMMITED로 유지
📚 기타