-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor/#803 행사 및 함께해요 관련 api 명세 수정 #808
The head ref may contain hidden characters: "Refactor/#803-\uD589\uC0AC_\uBC0F_\uD568\uAED8\uD574\uC694_\uAD00\uB828_API_\uBA85\uC138_\uC218\uC815"
Conversation
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.
일단 간단하게 한 번 훑어봤어요 RC 날릴겡
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; |
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.
이 클래스 이름을 EvnetResponse로 바꾸는 건 어때요? Detail보단, 그게 나을 것 같아서요
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.
반영했습니당
for (Image image : images) { | ||
imageUrlPerEventId.put(image.getContentId(), image.getName()); | ||
|
||
Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>(); |
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.
stream으로 풀어볼수도 있지 않을까요?
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.
전에 어디선가 코드리뷰 받으면서 알게된 건데 stream.forEach()로 원소를 순회하게 되면, 도중에 예외가 발생했을 때 순회가 중단되지 않고 순회를 마친 후 예외가 던져진다고 하더라구요.
그래서 저는 반복문 내에 레파지토리를 조회하는 로직이 포함된 경우 for문으로 풀어서 작성하고 있습니다.
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.
그 stream.forEach()로 원소순회 시 예외 발생하면 순회를 마친 후 예외가 던져진다.
는 아마 내가 알려줬던 것 같은데, 기억하고 있네
나는 반복문 내에 Repository에서 조회 로직이 필요하도록 짰다면 다른 방식을 한번 고민해볼것 같아.
지금 그러면 쿼리가 event 수만큼 나가고 있는 거잖아.
내 생각엔 findAllByEventIds(eventIds)를 하고, 그 다음에 grouping을 할 수도 있을 것 같은데, 어떻게 생각해?
그러면 쿼리가 훨씬 줄 것 같아서
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.
아아 그런 방법이 있었네
바로 반영했어
하는김에 중복 코드들을 ImageQueryService를 만들어서 옮겼습니당
for (Image image : images) { | ||
imageUrlPerEventId.put(image.getContentId(), image.getName()); | ||
|
||
Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>(); |
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.
final 붙여주세용
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.
반영했습니다!
final List<String> informationImageUrls = extractInformationImages(imageUrls); | ||
.collect(toList())); | ||
final String thumbnailImageUrl = images.extractThumbnailImage(); | ||
final List<String> informationImageUrls = images.extractInformationImages(); | ||
return EventDetailResponse.from(event, thumbnailImageUrl, informationImageUrls); |
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.
아예 파라미터로 Images를 넘겨도 좋을 것 같네요
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.
좋은 아이디어 감사합니다~~ 반영했습니다!
return images.stream() | ||
.filter(Image::isThumbnail) | ||
.findFirst() | ||
.orElseThrow() |
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.
orElseThrow에서 Exception을 지정하고 테스트를 짜보면 좋을 것 같아
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.
헐 커스텀 예외 만들려고 생각했었는데 잊어버렸나보다...
알려줘서 고마워 바로 반영할게
final Map<Long, AllImagesOfContent> imagesPerEventId) { | ||
return events.stream() | ||
.map(event -> { | ||
final AllImagesOfContent allImageUrls = imagesPerEventId.get(event.getId()); |
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.
이정도 사이즈의 메서드라면 별도로 분리하는건 어떨까?
그리고 Collect할 때 UnModifiableList로 해줄 수 있겠니
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.
반영했습니당
) { | ||
return groupByEventStatus.values().stream() | ||
.map(events -> makeEventResponsesByStatus(events, imagesPerEventId)) | ||
.reduce(new ArrayList<>(), (combinedEvents, eventsToAdd) -> { |
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.
이정도면 아마 reduce(new ArrayList<>(), List::addAll)로 할 수 있지 않나?
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.
아 그거 처음에 그렇게 하려고 했는데 addAll의 반환 타입이 boolean이라 안되는 걸로 알고있어용
@@ -65,4 +70,28 @@ public static EventDetailResponse from( | |||
event.getEventMode().getValue() | |||
); | |||
} | |||
|
|||
public static List<EventDetailResponse> makeEventResponsesByStatus(final List<Event> events, |
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.
오키오키
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.
@hong-sile
리뷰 반영했습니당~~
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; |
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.
반영했습니당
final Map<Long, AllImagesOfContent> imagesPerEventId) { | ||
return events.stream() | ||
.map(event -> { | ||
final AllImagesOfContent allImageUrls = imagesPerEventId.get(event.getId()); |
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.
반영했습니당
) { | ||
return groupByEventStatus.values().stream() | ||
.map(events -> makeEventResponsesByStatus(events, imagesPerEventId)) | ||
.reduce(new ArrayList<>(), (combinedEvents, eventsToAdd) -> { |
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.
아 그거 처음에 그렇게 하려고 했는데 addAll의 반환 타입이 boolean이라 안되는 걸로 알고있어용
return images.stream() | ||
.filter(Image::isThumbnail) | ||
.findFirst() | ||
.orElseThrow() |
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.
헐 커스텀 예외 만들려고 생각했었는데 잊어버렸나보다...
알려줘서 고마워 바로 반영할게
@@ -65,4 +70,28 @@ public static EventDetailResponse from( | |||
event.getEventMode().getValue() | |||
); | |||
} | |||
|
|||
public static List<EventDetailResponse> makeEventResponsesByStatus(final List<Event> events, |
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.
오키오키
final List<String> informationImageUrls = extractInformationImages(imageUrls); | ||
.collect(toList())); | ||
final String thumbnailImageUrl = images.extractThumbnailImage(); | ||
final List<String> informationImageUrls = images.extractInformationImages(); | ||
return EventDetailResponse.from(event, thumbnailImageUrl, informationImageUrls); |
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.
좋은 아이디어 감사합니다~~ 반영했습니다!
for (Image image : images) { | ||
imageUrlPerEventId.put(image.getContentId(), image.getName()); | ||
|
||
Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>(); |
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.
전에 어디선가 코드리뷰 받으면서 알게된 건데 stream.forEach()로 원소를 순회하게 되면, 도중에 예외가 발생했을 때 순회가 중단되지 않고 순회를 마친 후 예외가 던져진다고 하더라구요.
그래서 저는 반복문 내에 레파지토리를 조회하는 로직이 포함된 경우 for문으로 풀어서 작성하고 있습니다.
for (Image image : images) { | ||
imageUrlPerEventId.put(image.getContentId(), image.getName()); | ||
|
||
Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>(); |
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.
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.
- 단건 조회, 다건 조회 API에 적용 #803
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.
일단 이번 목표는 명세를 수정하는 거니, 더 리팩터링 관련해선 리뷰를 안 남길게요. 수고했슴다
for (Image image : images) { | ||
imageUrlPerEventId.put(image.getContentId(), image.getName()); | ||
|
||
Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>(); |
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.
그 stream.forEach()로 원소순회 시 예외 발생하면 순회를 마친 후 예외가 던져진다.
는 아마 내가 알려줬던 것 같은데, 기억하고 있네
나는 반복문 내에 Repository에서 조회 로직이 필요하도록 짰다면 다른 방식을 한번 고민해볼것 같아.
지금 그러면 쿼리가 event 수만큼 나가고 있는 거잖아.
내 생각엔 findAllByEventIds(eventIds)를 하고, 그 다음에 grouping을 할 수도 있을 것 같은데, 어떻게 생각해?
그러면 쿼리가 훨씬 줄 것 같아서
return new ArrayList<>(); | ||
} | ||
|
||
return tags.stream() |
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.
여기 작업하는 부분이 아니긴 하지만, 이런 것도 엄청 쿼리가 많이 나가는 부분이잖아 In절 쿼리로 한번에 조회하도록 할 수있을 것 같은데?
tagRepository.findByNames(tagNames)
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.
반영했어~~!
final String thumbnailImageUrl = savedImages.extractThumbnailImage(); | ||
final List<String> informationImageUrls = savedImages.extractInformationImages(); | ||
return EventResponse.from(event, thumbnailImageUrl, informationImageUrls); | ||
return EventResponse.from(event, savedImages); |
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.
넵...!👀
- 스크랩 행사 목록 조회 시 행사마다 image 조회 쿼리가 나가는 대신 행사들의 이미지를 모두 불러온 후 그룹핑되도록 수정 - 코드 중복을 없애기 위한 ImageQueryService 추가 #803
#️⃣ 연관된 이슈
📝 작업 내용
행사 및 함께해요 조회 API 명세 수정 및 자잘한 변경사항 반영
예상 소요 시간 및 실제 소요 시간 (일 / 시간 / 분)
예상 소요 시간 : 10/30
실제 소요 시간 : 10/30