-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Member 탈퇴에 따른 엔티티 Soft Delete 처리 성능 개선 (#704)
* feat: memberId로 tripId 리스트 반환하는 기능 추가 * feat: tripId 리스트로 dayLogId 리스트 반환하는 기능 추가 * feat: dayLogId 리스트로 itemId 리스트 반환하는 기능 추가 * refactor: itemId, placeId, expenseId를 가진 DTO 리스트 반환하도록 변경 * refactor: memberId에 따른 엔티티 status 변경 및 refreshToken 삭제 성능 개선 * refactor: repository 구현체 패키지 변경 * refactor: SharedTrip, PublishedTrip도 함께 업데이트되도록 변경 * refactor: event 적용 * refactor: 트랜잭션 분리 * refactor: `@Async`로 비동기 처리 * refactor: 메서드 분리 * test: AuthServiceIntegrationTest 수정 * test: MemberDeleteEventListener Mock Test 작성 * refactor: indent 변경 * refactor: final 추가 * refactor: event 관련 클래스 패키지 위치 변경 * refactor: SharedStatusType 위치 변경 * refactor: WriterResponse 위치 변경 * refactor: PublishedStatusType 위치 변경
- Loading branch information
Showing
41 changed files
with
463 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
2 changes: 1 addition & 1 deletion
2
backend/src/main/java/hanglog/community/service/CommunityService.java
This file contains 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
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/expense/domain/repository/ExpenseRepository.java
This file contains 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,7 +1,19 @@ | ||
package hanglog.expense.domain.repository; | ||
|
||
import hanglog.expense.domain.Expense; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ExpenseRepository extends JpaRepository<Expense, Long> { | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE Expense expense | ||
SET expense.status = 'DELETED' | ||
WHERE expense.id IN :expenseIds | ||
""") | ||
void deleteByIds(@Param("expenseIds") final List<Long> expenseIds); | ||
} |
This file contains 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
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/image/domain/repository/ImageRepository.java
This file contains 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,7 +1,19 @@ | ||
package hanglog.image.domain.repository; | ||
|
||
import hanglog.image.domain.Image; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ImageRepository extends JpaRepository<Image, Long> { | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE Image image | ||
SET image.status = 'DELETED' | ||
WHERE image.item.id IN :itemIds | ||
""") | ||
void deleteByItemIds(@Param("itemIds") final List<Long> itemIds); | ||
} |
76 changes: 76 additions & 0 deletions
76
backend/src/main/java/hanglog/listener/MemberDeleteEventListener.java
This file contains 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,76 @@ | ||
package hanglog.listener; | ||
|
||
import hanglog.auth.domain.repository.RefreshTokenRepository; | ||
import hanglog.expense.domain.repository.ExpenseRepository; | ||
import hanglog.image.domain.repository.ImageRepository; | ||
import hanglog.member.domain.MemberDeleteEvent; | ||
import hanglog.trip.domain.repository.CustomDayLogRepository; | ||
import hanglog.trip.domain.repository.CustomItemRepository; | ||
import hanglog.trip.domain.repository.DayLogRepository; | ||
import hanglog.trip.domain.repository.ItemRepository; | ||
import hanglog.trip.domain.repository.PlaceRepository; | ||
import hanglog.trip.domain.repository.TripRepository; | ||
import hanglog.trip.dto.ItemElement; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MemberDeleteEventListener { | ||
|
||
private final CustomDayLogRepository customDayLogRepository; | ||
private final CustomItemRepository customItemRepository; | ||
private final PlaceRepository placeRepository; | ||
private final ExpenseRepository expenseRepository; | ||
private final ImageRepository imageRepository; | ||
private final ItemRepository itemRepository; | ||
private final DayLogRepository dayLogRepository; | ||
private final TripRepository tripRepository; | ||
private final RefreshTokenRepository refreshTokenRepository; | ||
|
||
@Async | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(fallbackExecution = true) | ||
public void delete(final MemberDeleteEvent event) { | ||
final List<Long> dayLogIds = customDayLogRepository.findDayLogIdsByTripIds(event.getTripIds()); | ||
final List<ItemElement> itemElements = customItemRepository.findItemIdsByDayLogIds(dayLogIds); | ||
|
||
deletePlaces(itemElements); | ||
deleteExpenses(itemElements); | ||
deleteImageAndItems(itemElements); | ||
|
||
dayLogRepository.deleteByIds(dayLogIds); | ||
tripRepository.deleteByMemberId(event.getMemberId()); | ||
refreshTokenRepository.deleteByMemberId(event.getMemberId()); | ||
} | ||
|
||
private void deletePlaces(final List<ItemElement> itemElements) { | ||
final List<Long> placeIds = itemElements.stream() | ||
.map(ItemElement::getPlaceId) | ||
.toList(); | ||
|
||
placeRepository.deleteByIds(placeIds); | ||
} | ||
|
||
private void deleteExpenses(final List<ItemElement> itemElements) { | ||
final List<Long> expenseIds = itemElements.stream() | ||
.map(ItemElement::getExpenseId) | ||
.toList(); | ||
|
||
expenseRepository.deleteByIds(expenseIds); | ||
} | ||
|
||
private void deleteImageAndItems(final List<ItemElement> itemElements) { | ||
final List<Long> itemIds = itemElements.stream() | ||
.map(ItemElement::getItemId) | ||
.toList(); | ||
|
||
imageRepository.deleteByItemIds(itemIds); | ||
itemRepository.deleteByIds(itemIds); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/hanglog/member/domain/MemberDeleteEvent.java
This file contains 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,13 @@ | ||
package hanglog.member.domain; | ||
|
||
import java.util.List; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class MemberDeleteEvent { | ||
|
||
private final List<Long> tripIds; | ||
private final Long memberId; | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
...og/share/dto/response/WriterResponse.java → ...g/member/dto/response/WriterResponse.java
This file contains 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
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/share/domain/repository/SharedTripRepository.java
This file contains 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,10 +1,22 @@ | ||
package hanglog.share.domain.repository; | ||
|
||
import hanglog.share.domain.SharedTrip; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface SharedTripRepository extends JpaRepository<SharedTrip, Long> { | ||
|
||
Optional<SharedTrip> findBySharedCode(final String sharedCode); | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE SharedTrip sharedTrip | ||
SET sharedTrip.status = 'DELETED' | ||
WHERE sharedTrip.trip.id IN :tripIds | ||
""") | ||
void deleteByTripIds(@Param("tripIds") final List<Long> tripIds); | ||
} |
This file contains 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 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
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/hanglog/trip/domain/repository/CustomItemRepository.java
This file contains 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,9 @@ | ||
package hanglog.trip.domain.repository; | ||
|
||
import hanglog.trip.dto.ItemElement; | ||
import java.util.List; | ||
|
||
public interface CustomItemRepository { | ||
|
||
List<ItemElement> findItemIdsByDayLogIds(final List<Long> dayLogIds); | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/hanglog/trip/domain/repository/CustomTripRepository.java
This file contains 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,8 @@ | ||
package hanglog.trip.domain.repository; | ||
|
||
import java.util.List; | ||
|
||
public interface CustomTripRepository { | ||
|
||
List<Long> findTripIdsByMemberId(final Long memberId); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/trip/domain/repository/DayLogRepository.java
This file contains 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,7 +1,19 @@ | ||
package hanglog.trip.domain.repository; | ||
|
||
import hanglog.trip.domain.DayLog; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface DayLogRepository extends JpaRepository<DayLog, Long> { | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE DayLog dayLog | ||
SET dayLog.status = 'DELETED' | ||
WHERE dayLog.id IN :dayLogIds | ||
""") | ||
void deleteByIds(@Param("dayLogIds") final List<Long> dayLogIds); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/trip/domain/repository/ItemRepository.java
This file contains 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,7 +1,19 @@ | ||
package hanglog.trip.domain.repository; | ||
|
||
import hanglog.trip.domain.Item; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ItemRepository extends JpaRepository<Item, Long> { | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE Item item | ||
SET item.status = 'DELETED' | ||
WHERE item.id IN :itemIds | ||
""") | ||
void deleteByIds(@Param("itemIds") final List<Long> itemIds); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/trip/domain/repository/PlaceRepository.java
This file contains 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,7 +1,19 @@ | ||
package hanglog.trip.domain.repository; | ||
|
||
import hanglog.trip.domain.Place; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface PlaceRepository extends JpaRepository<Place, Long> { | ||
|
||
@Modifying | ||
@Query(""" | ||
UPDATE Place place | ||
SET place.status = 'DELETED' | ||
WHERE place.id IN :placeIds | ||
""") | ||
void deleteByIds(@Param("placeIds") final List<Long> placeIds); | ||
} |
Oops, something went wrong.