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

비동기 메서드에서 엔티티 객체를 직접 조회하도록 수정하여 트랜잭션 반영 문제 해결 #837

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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
Loading