-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] s3 삭제 건너뛰기 구현 #368
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
Merged
Merged
[FEAT] s3 삭제 건너뛰기 구현 #368
Changes from all commits
Commits
Show all changes
4 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
42 changes: 34 additions & 8 deletions
42
...ain/java/issueissyu/backend/domain/community/service/command/CommunicationPinCleaner.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 |
|---|---|---|
| @@ -1,26 +1,52 @@ | ||
| package issueissyu.backend.domain.community.service.command; | ||
|
|
||
| import issueissyu.backend.utils.S3.S3Utils; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.transaction.support.TransactionSynchronization; | ||
| import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CommunicationPinCleaner { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
| private final S3Utils s3Utils; | ||
|
|
||
| @Transactional | ||
| public void deleteByPinId(Long pinId) { | ||
| jdbcTemplate.update("DELETE FROM pin_emoji WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM declaration WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM \"comment\" WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_like WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM community WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_location WHERE pin_id = ?", pinId); | ||
| // DB 삭제 전에 pin_image S3 key 수집 | ||
| List<String> pinImageKeys = jdbcTemplate.queryForList( | ||
| "SELECT pin_s3_key FROM pin_image WHERE pin_id = ?", | ||
| String.class, pinId); | ||
|
|
||
| jdbcTemplate.update("DELETE FROM pin_emoji WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM declaration WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM \"comment\" WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_like WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM community WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_location WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM communication_pin WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_image WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin_image WHERE pin_id = ?", pinId); | ||
| jdbcTemplate.update("DELETE FROM pin WHERE pin_id = ?", pinId); | ||
|
|
||
| // DB 삭제 완료 후 트랜잭션 커밋이 성공하면 S3 객체 삭제 | ||
| if (TransactionSynchronizationManager.isSynchronizationActive()) { | ||
| TransactionSynchronizationManager.registerSynchronization( | ||
| new TransactionSynchronization() { | ||
| @Override | ||
| public void afterCommit() { | ||
| pinImageKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
| }); | ||
| } else { | ||
| pinImageKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
| } | ||
| } |
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
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
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.