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

[feat/CK-237] 골룸 참여 시 발생하는 동시성 이슈를 해결한다 #199

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public interface GoalRoomQueryRepository {

Optional<GoalRoom> findGoalRoomByIdWithPessimisticLock(Long goalRoomId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final 붙여주세요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Optional<GoalRoom> findByIdWithRoadmapContent(final Long goalRoomId);

Optional<GoalRoom> findByIdWithContentAndTodos(final Long goalRoomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import jakarta.persistence.LockModeType;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
Expand All @@ -27,6 +28,16 @@ public GoalRoomQueryRepositoryImpl() {
super(GoalRoom.class);
}

@Override
public Optional<GoalRoom> findGoalRoomByIdWithPessimisticLock(final Long goalRoomId) {
return Optional.ofNullable(selectFrom(goalRoom)
.innerJoin(goalRoom.goalRoomPendingMembers.values, goalRoomPendingMember)
.fetchJoin()
.where(goalRoom.id.eq(goalRoomId))
.setLockMode(LockModeType.PESSIMISTIC_WRITE)
.fetchOne());
}

@Override
public Optional<GoalRoom> findByIdWithRoadmapContent(final Long goalRoomId) {
return Optional.ofNullable(selectFrom(goalRoom)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package co.kirikiri.persistence.goalroom;

import co.kirikiri.domain.goalroom.GoalRoom;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface GoalRoomRepository extends JpaRepository<GoalRoom, Long>, GoalRoomQueryRepository {

@Override

Optional<GoalRoom> findById(final Long goalRoomId);

List<GoalRoom> findAllByEndDate(final LocalDate endDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void join(final String identifier, final Long goalRoomId) {
}

private GoalRoom findGoalRoomById(final Long goalRoomId) {
return goalRoomRepository.findById(goalRoomId)
return goalRoomRepository.findGoalRoomByIdWithPessimisticLock(goalRoomId)
.orElseThrow(() -> new NotFoundException("존재하지 않는 골룸입니다. goalRoomId = " + goalRoomId));
}

Expand Down
Loading