-
Notifications
You must be signed in to change notification settings - Fork 2
perf: 성능 보고서 기반 최적화 — 쪽지 이메일 비동기화 + Redis 왕복 축소 #349
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
Open
GOOHAESEUNG
wants to merge
2
commits into
dev
Choose a base branch
from
perf/report-optimizations
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/com/tavemakers/surf/application/letter/event/LetterEmailListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.tavemakers.surf.application.letter.event; | ||
|
|
||
| import com.tavemakers.surf.domain.letter.event.LetterEmailRequestedEvent; | ||
| import com.tavemakers.surf.global.util.EmailSender; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.mail.MailException; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.event.TransactionPhase; | ||
| import org.springframework.transaction.event.TransactionalEventListener; | ||
|
|
||
| /** | ||
| * 쪽지 이메일 발송 리스너 — 커밋 후 비동기로 SMTP 발송을 수행한다. | ||
| * <p>기존에는 요청 스레드에서 동기 발송해 응답이 SMTP 왕복(~3초)만큼 지연됐다. | ||
| * 발송 실패는 응답에 영향을 주지 않으며 서버 로그로만 남긴다(쪽지 저장은 이미 커밋됨). | ||
| * LogEventEmitter는 요청 스레드 ThreadLocal 기반이라 비동기 스레드에서는 slf4j로 기록한다. | ||
| */ | ||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class LetterEmailListener { | ||
|
|
||
| private final EmailSender emailSender; | ||
|
|
||
| /** 쪽지 이메일 발송 (AFTER_COMMIT + 비동기) */ | ||
| @Async | ||
| @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
| public void handle(LetterEmailRequestedEvent event) { | ||
| String body = """ | ||
| [Surf에서 %s님이 보낸 쪽지입니다.] | ||
|
|
||
| %s | ||
|
|
||
| 회신 희망 이메일: %s | ||
| SNS: %s | ||
| """ | ||
| .formatted( | ||
| event.senderName(), | ||
| event.content(), | ||
| event.replyEmail(), | ||
| event.sns() != null ? event.sns() : "-" | ||
| ); | ||
|
|
||
| try { | ||
| emailSender.sendMail(event.receiverEmail(), event.title(), body); | ||
| log.info("[LetterEmail] sent letterId={} senderId={} receiverId={}", | ||
| event.letterId(), event.senderId(), event.receiverId()); | ||
| } catch (MailException e) { | ||
| log.error("[LetterEmail] send failed letterId={} senderId={} receiverId={} - {}", | ||
| event.letterId(), event.senderId(), event.receiverId(), e.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/tavemakers/surf/domain/letter/event/LetterEmailRequestedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.tavemakers.surf.domain.letter.event; | ||
|
|
||
| /** 쪽지 저장 커밋 후 수신자에게 이메일을 발송하기 위한 이벤트 (리스너: application/letter/event) */ | ||
| public record LetterEmailRequestedEvent( | ||
| Long letterId, | ||
| Long senderId, | ||
| Long receiverId, | ||
| String senderName, | ||
| String receiverEmail, | ||
| String title, | ||
| String content, | ||
| String replyEmail, | ||
| String sns | ||
| ) { | ||
| } |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/tavemakers/surf/domain/letter/exception/LetterMailSendFailException.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.