Skip to content

Commit

Permalink
fix: 비동기 메서드에서 엔티티 객체를 직접 조회하도록 수정하여 트랜잭션 반영 문제 해결 (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanjaemo authored Jan 3, 2025
1 parent 8a59b11 commit ebb55e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Long createTalkPick(CreateTalkPickRequest request, ApiMember apiMember) {
talkPickFileHandler.handleFilesOnTalkPickCreate(request.getFileIds(), savedTalkPickId);
}

talkPickSummarizer.summary(savedTalkPick);
talkPickSummarizer.summary(savedTalkPickId);

return savedTalkPickId;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public void updateTalkPick(Long talkPickId, UpdateTalkPickRequest request, ApiMe
talkPick.update(request.toEntity(member));
talkPickFileHandler
.handleFilesOnTalkPickUpdate(request.getNewFileIds(), request.getDeleteFileIds(), talkPickId);
talkPickSummarizer.summary(talkPick);
talkPickSummarizer.summary(talkPickId);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package balancetalk.talkpick.domain;

import static balancetalk.global.exception.ErrorCode.NOT_FOUND_TALK_PICK;
import static balancetalk.global.exception.ErrorCode.TALK_PICK_SUMMARY_FAILED;
import static balancetalk.global.exception.ErrorCode.TALK_PICK_SUMMARY_SIZE_IS_OVER;
import static balancetalk.talkpick.domain.SummaryStatus.FAIL;
import static balancetalk.talkpick.domain.SummaryStatus.NOT_REQUIRED;
import static balancetalk.talkpick.domain.SummaryStatus.SUCCESS;

import balancetalk.global.exception.BalanceTalkException;
import balancetalk.talkpick.domain.repository.TalkPickRepository;
import balancetalk.talkpick.dto.fields.BaseTalkPickFields;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -51,11 +53,15 @@ public class TalkPickSummarizer {
""";

private final ChatClient chatClient;
private final TalkPickRepository talkPickRepository;

@Async
@Retryable(backoff = @Backoff(delay = 1000), maxAttempts = 3)
@Transactional
public void summary(TalkPick talkPick) {
public void summary(Long talkPickId) {
TalkPick talkPick = talkPickRepository.findById(talkPickId)
.orElseThrow(() -> new BalanceTalkException(NOT_FOUND_TALK_PICK));

// 본문 글자수가 너무 짧으면 요약 제공 안함
if (talkPick.hasShortContent()) {
talkPick.updateSummaryStatus(NOT_REQUIRED);
Expand Down

0 comments on commit ebb55e3

Please sign in to comment.