-
Notifications
You must be signed in to change notification settings - Fork 0
[DEPLOY] production-release(v.0.3.2) #372
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
Changes from all commits
f5382fa
9a6fa25
bd4e1c8
00fb6f3
120e86d
b1f5ff2
321dac6
7a6cb78
4b2828f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| package issueissyu.backend.domain.community.service.command; | ||
|
|
||
| import issueissyu.backend.domain.community.entity.CardnewsImageS3; | ||
| import issueissyu.backend.domain.community.entity.Community; | ||
| import issueissyu.backend.domain.community.enums.CommunityType; | ||
| import issueissyu.backend.domain.community.exception.CommunityException; | ||
| import issueissyu.backend.domain.community.exception.code.CommunityErrorCode; | ||
| import issueissyu.backend.domain.community.repository.CardnewsImageS3Repository; | ||
| import issueissyu.backend.domain.community.repository.CommunityRepository; | ||
| import issueissyu.backend.utils.S3.S3Utils; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.transaction.support.TransactionSynchronization; | ||
| import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
|
|
@@ -16,6 +23,8 @@ public class CommunityCommandServiceImpl implements CommunityCommandService { | |
|
|
||
| private final CommunityRepository communityRepository; | ||
| private final CommunicationPinCleaner communicationPinCleaner; | ||
| private final CardnewsImageS3Repository cardnewsImageS3Repository; | ||
| private final S3Utils s3Utils; | ||
|
|
||
| @Override | ||
| public void deleteCommunity(Long communityId, String uid) { | ||
|
|
@@ -45,6 +54,29 @@ public void takedownCommunity(Long communityId, String uid) { | |
| if (!community.getPin().getUser().getUid().equals(uid)) { | ||
| throw CommunityException.of(CommunityErrorCode.COMMUNITY_403_3); | ||
| } | ||
|
|
||
| // cardnews_image_s3๋ Community์ cascade๊ฐ ์์ผ๋ฏ๋ก ๋ช ์์ ์ผ๋ก ๋จผ์ ์ญ์ | ||
| // findDetailById์์ left join fetch๋ก ๋ก๋๋ ๋ฐ์ดํฐ๋ฅผ ํ์ฉ | ||
| List<String> cardnewsKeys = community.getCardnewsImages().stream() | ||
| .map(CardnewsImageS3::getCardnewsImageS3Key) | ||
| .toList(); | ||
| if (!cardnewsKeys.isEmpty()) { | ||
| cardnewsImageS3Repository.deleteByCommunity_CommunityId(communityId); | ||
| } | ||
|
|
||
| communityRepository.delete(community); | ||
|
|
||
| // DB ์ญ์ ์๋ฃ ํ ํธ๋์ญ์ ์ปค๋ฐ์ด ์ฑ๊ณตํ๋ฉด S3 ๊ฐ์ฒด ์ญ์ | ||
| if (TransactionSynchronizationManager.isSynchronizationActive()) { | ||
| TransactionSynchronizationManager.registerSynchronization( | ||
| new TransactionSynchronization() { | ||
| @Override | ||
| public void afterCommit() { | ||
| cardnewsKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
| }); | ||
| } else { | ||
| cardnewsKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
|
Comment on lines
+60
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์ถ๊ฐ๋ก, ํธ๋์ญ์
์ปค๋ฐ ํ( List<String> cardnewsKeys = community.getCardnewsImages() == null ? List.of() : community.getCardnewsImages().stream()
.map(CardnewsImageS3::getCardnewsImageS3Key)
.filter(key -> key != null && !key.isBlank())
.toList();
if (!cardnewsKeys.isEmpty()) {
cardnewsImageS3Repository.deleteByCommunity_CommunityId(communityId);
}
communityRepository.delete(community);
if (!cardnewsKeys.isEmpty()) {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronization() {
@Override
public void afterCommit() {
cardnewsKeys.forEach(s3Utils::deleteIfNotReserved);
}
});
} else {
cardnewsKeys.forEach(s3Utils::deleteIfNotReserved);
}
} |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ | |
| import org.postgresql.geometric.PGpoint; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.transaction.support.TransactionSynchronization; | ||
| import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.time.LocalDateTime; | ||
|
|
@@ -293,9 +295,27 @@ private boolean syncPinImages(Pin pin, List<PinImageItemReqDTO> items) { | |
| boolean changed = false; | ||
| Set<String> keepUrls = items.stream().map(PinImageItemReqDTO::pinImageUrl).collect(Collectors.toSet()); | ||
|
|
||
| // ์ ๊ฑฐ ๋์ key๋ฅผ removeIf ์ ์ ๋จผ์ ์์ง (orphanRemoval๋ก DB ์ญ์ ๋๊ธฐ ์ ) | ||
| List<String> removedKeys = pin.getPinImages().stream() | ||
| .filter(pi -> !keepUrls.contains(pi.getPinS3Url())) | ||
| .map(PinImage::getPinS3Key) | ||
| .filter(key -> key != null && !key.isBlank()) | ||
| .toList(); | ||
|
|
||
| boolean removedAny = pin.getPinImages().removeIf(pi -> !keepUrls.contains(pi.getPinS3Url())); | ||
| if (removedAny) { | ||
| changed = true; | ||
| if (TransactionSynchronizationManager.isSynchronizationActive()) { | ||
| TransactionSynchronizationManager.registerSynchronization( | ||
| new TransactionSynchronization() { | ||
| @Override | ||
| public void afterCommit() { | ||
| removedKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
| }); | ||
| } else { | ||
| removedKeys.forEach(s3Utils::deleteIfNotReserved); | ||
| } | ||
| } | ||
|
Comment on lines
+298
to
319
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// ์ ๊ฑฐ ๋์ key๋ฅผ removeIf ์ ์ ๋จผ์ ์์ง (orphanRemoval๋ก DB ์ญ์ ๋๊ธฐ ์ )
List<String> removedKeys = pin.getPinImages().stream()
.filter(pi -> !keepUrls.contains(pi.getPinS3Url()))
.map(PinImage::getPinS3Key)
.filter(key -> key != null && !key.isBlank())
.toList();
boolean removedAny = pin.getPinImages().removeIf(pi -> !keepUrls.contains(pi.getPinS3Url()));
if (removedAny) {
changed = true;
}
if (!removedKeys.isEmpty()) {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronization() {
@Override
public void afterCommit() {
removedKeys.forEach(s3Utils::deleteIfNotReserved);
}
});
} else {
removedKeys.forEach(s3Utils::deleteIfNotReserved);
}
} |
||
|
|
||
| for (PinImageItemReqDTO item : items) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์กฐํํ
pinImageKeys๋ชฉ๋ก์null์ด๋ ๋น ๋ฌธ์์ด์ด ํฌํจ๋์ด ์์ ๊ฐ๋ฅ์ฑ์ ๋ฐฉ์งํ๊ธฐ ์ํด ํํฐ๋ง์ ์ถ๊ฐํ๊ณ , ์ญ์ ํ ํค๊ฐ ์์ ๋๋ ๋ถํ์ํ ํธ๋์ญ์ ๋๊ธฐํ ๋ฑ๋ก์ ๊ฑด๋๋ฐ๋๋ก ๊ฐ์ ํ๋ ๊ฒ์ด ์์ ํฉ๋๋ค.