Skip to content
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

[BE] 메세지 좋아요의 동시성 이슈를 해결한다. #631

Open
asebn1 opened this issue Oct 27, 2022 · 0 comments
Open

[BE] 메세지 좋아요의 동시성 이슈를 해결한다. #631

asebn1 opened this issue Oct 27, 2022 · 0 comments
Assignees
Projects

Comments

@asebn1
Copy link
Collaborator

asebn1 commented Oct 27, 2022

기능 상세

  • 메세지 좋아요를 여러번 눌렀을 때 DB에 연속으로 쌓이는 이슈가 발생하였습니다.

image

메세지 좋아요에 엄청난 연타를 해보았을 때 다음과같은 이슈가 발생하였습니다.

중복된 데이터가 쌓였습니다!

  • 메세지 좋아요 테이블에는 같은 member_id, message_id가 공존하면 안됩니다.

image

기존 코드

public MessageLikeResponseDto likeMessage(Long memberId, Long rollingpaperId, Long messageId) {
		// 메세지 좋아요 대상 "메세지"를 찾는다.
    final Message message = messageRepository.findById(messageId)
            .orElseThrow(() -> new NotFoundMessageException(messageId));
		// "메세지 좋아요" 테이블에 존재하면 에러를 던진다.
    if (messageLikeRepository.existsByMemberIdAndMessageId(memberId, messageId)) {
        throw new InvalidLikeMessageException(messageId, messageId);
    }
		// 메세지 좋아요 추가
    message.like();
    messageLikeRepository.save(new MessageLike(memberId, rollingpaperId, messageId));
    return new MessageLikeResponseDto(message.getLikes(), true);
}
  1. 메세지 좋아요 대상 "메세지"를 찾습니다.
  2. "메세지 좋아요" 테이블에 기록이 존재하면 에러를 던집니다.
  3. 메세지 좋아요를 추가한다.
@asebn1 asebn1 self-assigned this Oct 27, 2022
@asebn1 asebn1 added this to To do in Sprint 6 via automation Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant