-
Notifications
You must be signed in to change notification settings - Fork 16
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
DeleteEventListener 내부 로직 비동기 처리 #748
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package hanglog.listener; | ||
|
||
import hanglog.expense.domain.repository.ExpenseRepository; | ||
import hanglog.login.domain.repository.RefreshTokenRepository; | ||
import hanglog.trip.domain.repository.DayLogRepository; | ||
import hanglog.trip.domain.repository.ImageRepository; | ||
import hanglog.trip.domain.repository.ItemRepository; | ||
import hanglog.trip.domain.repository.PlaceRepository; | ||
import hanglog.trip.domain.repository.TripCityRepository; | ||
import hanglog.trip.domain.repository.TripRepository; | ||
import hanglog.trip.dto.ItemElement; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public class TransactionalDeleteProcessor { | ||
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. 특정한 로직을 transactional하게 delete해준다는 invoker느낌이 강해지는 것 같네요! 이젠 얘한테 void타입의 delete로직을 수행하는 함수형인터페이스를 넘겨줘서 실행해도 괜찮겠다는 생각이 ......... 들었습니다... 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. 이런 느낌일까요? public void invoke(final Long memberId, final DeleteInvoker invoker) {
tripDeleteInvoker.delete(memberId, tripRepository);
}
transactionalDeleteProcessor
.invoke(
event.getMemberId(),
(Long memberId, TripRepository repository) -> repository.deleteByMemberId(memberId)
); 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. 굉장합니다! invoke의 인자로 익명클래스만 받아도 될 것 같습니다! memberId라는 인자에 국한되지 않아도 될 것 같습니다. AsyncDeleteProcessor or TransactionalDeleteProcessor라는 클래스를 만들거라면 이 방식도 괜찮아보입니다. 물론 전 Delete가 집중하지 말고 각 도메인별로 이벤트리스너만들자 파이긴합니다!!! |
||
|
||
private final PlaceRepository placeRepository; | ||
private final ExpenseRepository expenseRepository; | ||
private final ImageRepository imageRepository; | ||
private final ItemRepository itemRepository; | ||
private final DayLogRepository dayLogRepository; | ||
private final TripCityRepository tripCityRepository; | ||
private final TripRepository tripRepository; | ||
private final RefreshTokenRepository refreshTokenRepository; | ||
|
||
public void deleteTrips(final Long memberId) { | ||
tripRepository.deleteByMemberId(memberId); | ||
} | ||
|
||
public void deleteTripCitesByTripId(final Long tripId) { | ||
tripCityRepository.deleteAllByTripId(tripId); | ||
} | ||
|
||
public void deleteTripCitesByTripIds(final List<Long> tripIds) { | ||
tripCityRepository.deleteAllByTripIds(tripIds); | ||
} | ||
|
||
public void deleteDayLogs(final List<Long> dayLogIds) { | ||
dayLogRepository.deleteByIds(dayLogIds); | ||
} | ||
|
||
public void deletePlaces(final List<ItemElement> itemElements) { | ||
final List<Long> placeIds = itemElements.stream() | ||
.map(ItemElement::getPlaceId) | ||
.toList(); | ||
placeRepository.deleteByIds(placeIds); | ||
} | ||
|
||
public void deleteExpenses(final List<ItemElement> itemElements) { | ||
final List<Long> expenseIds = itemElements.stream() | ||
.map(ItemElement::getExpenseId) | ||
.toList(); | ||
expenseRepository.deleteByIds(expenseIds); | ||
} | ||
|
||
public void deleteItems(final List<Long> itemIds) { | ||
itemRepository.deleteByIds(itemIds); | ||
} | ||
|
||
public void deleteImages(final List<Long> itemIds) { | ||
imageRepository.deleteByItemIds(itemIds); | ||
} | ||
|
||
public void deleteRefreshTokens(final Long memberId) { | ||
refreshTokenRepository.deleteByMemberId(memberId); | ||
} | ||
} |
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.
fallbackExecution=true 왜 지우셨나용?
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.
저번에 실험하다가 붙여놓고 까먹었습니다..
대충 요약하면
이런데 그냥 디폴트 해놔도 될듯...!
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.
현재 메서드에
@Transactional
이 붙어있으니 무조건 트랜잭션이 있는 상태에서 이벤트를 처리하므로 상관이 없다는 뜻 맞죠? 👍