Skip to content

Commit

Permalink
feat: Notification 생성 시 새로 save하는 경우 트랜잭션 분리한다
Browse files Browse the repository at this point in the history
Issue: #192
  • Loading branch information
melonturtle committed Mar 13, 2024
1 parent 061f4f0 commit 9efb24a
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
Expand Down Expand Up @@ -45,7 +46,11 @@ private Member findMember(Long memberId) {
}

//== notify ==//
@Transactional

/**
* Notification 생성 트랜잭션 분리하기 위해 새로운 트랜잭션에서 실행됨
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void notifyVoteResult(Topic topic) {
// voters' notifications
List<Member> voters = memberRepository.findAllListeningVoteResultAndVotedTopicId(topic.getId());
Expand Down Expand Up @@ -76,7 +81,10 @@ private void addAuthorsNotificationIfAuthorListeningVoteResult(Topic topic, List
}
}

@Transactional
/**
* Notification 생성 트랜잭션 분리하기 위해 새로운 트랜잭션에서 실행됨
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void notifyLikeInComment(LikedComment likedComment) {
if (shouldNotifyLikeInComment(likedComment)) {
LikeInCommentNotification notification = new LikeInCommentNotification(likedComment.getComment());
Expand All @@ -97,7 +105,10 @@ private boolean shouldNotifyLikeInComment(LikedComment likedComment) {
return !likerIsWriter && writerListenLikeInComment;
}

@Transactional
/**
* Notification 생성 트랜잭션 분리하기 위해 새로운 트랜잭션에서 실행됨
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void notifyCommentOnTopic(Comment comment) {
if (shouldNotifyCommentOnTopic(comment)) {
CommentOnTopicNotification notification = new CommentOnTopicNotification(comment);
Expand All @@ -117,7 +128,10 @@ private boolean shouldNotifyCommentOnTopic(Comment comment) {
return commenterIsNotAuthor && authorListenCommentOnTopic;
}

@Transactional
/**
* Notification 생성 트랜잭션 분리하기 위해 새로운 트랜잭션에서 실행됨
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void notifyVoteCountOnTopic(Topic topic) {
if (shouldNotifyVoteCountForTopic(topic)) {
VoteCountOnTopicNotification notification = new VoteCountOnTopicNotification(topic);
Expand Down

0 comments on commit 9efb24a

Please sign in to comment.