-
Notifications
You must be signed in to change notification settings - Fork 0
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
[COZY-445] refac: RoomStatUtil 분리 및 적용 #214
Conversation
리뷰해드려요~FavoriteQueryService.java
MateRepository.java
RoomRecommendConverter.java
RoomRecommendationResponseDTO.java
RoomQueryService.java
RoomRecommendService.java
RoomStatUtil.java
|
@@ -133,7 +133,7 @@ public List<FavoriteRoomResponseDTO> getFavoriteRoomList(Member member) { | |||
// <방 id, 해당 방의 mate 리스트> | |||
Map<Long, List<Mate>> roomIdMatesMap = responseRoomList.stream().collect( | |||
Collectors.toMap(Room::getId, | |||
room -> mateRepository.findFetchMemberByRoom(room, EntryStatus.JOINED))); | |||
room -> mateRepository.findFetchMemberAndMemberStatByRoom(room, EntryStatus.JOINED))); |
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.
mate의 Member와 Member의 MemberStat에 대한 쿼리가 추가로 날아가서 페치 조인으로 변경했습니다
? RoomStatUtil.getPreferenceStatsMatchCounts(member, criteriaPreferenceList, | ||
mates, memberStat) | ||
: RoomStatUtil.getPreferenceStatsMatchCountsWithoutMemberStat( | ||
criteriaPreferenceList); |
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.
유틸 클래스 사용으로 수정했습니다
List<String> roomHashTags = roomHashtagRepository.findHashtagsByRoomId( | ||
room.getId()); | ||
List<RoomHashtag> roomHashtags = room.getRoomHashtags(); | ||
List<String> roomHashTags = roomHashtags.stream() | ||
.map(RoomHashtag::getHashtag) | ||
.map(Hashtag::getHashtag) | ||
.toList(); |
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.
방 조회시 RoomHashTag도 같이 가져오는걸 확인해서 쿼리 안날리도록 수정했습니다
@@ -71,7 +72,7 @@ public RoomDetailResponseDTO getRoomById(Long roomId, Long memberId) { | |||
Map<Long, Integer> equalityMap = memberStatEqualityQueryService.getEquality(memberId, | |||
joinedMates.stream().map(mate -> mate.getMember().getId()).collect(Collectors.toList())); | |||
|
|||
Integer roomEquality = getCalculateRoomEquality(equalityMap); | |||
Integer roomEquality = RoomStatUtil.getCalculateRoomEquality(equalityMap); |
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.
RoomStatUtil 적용 1
@@ -209,7 +202,7 @@ public List<RoomDetailResponseDTO> getRoomList(Long memberId, EntryStatus entryS | |||
List<Mate> joinedMates = mateRepository.findAllByRoomIdAndEntryStatus(room.getId(), EntryStatus.JOINED); | |||
Map<Long, Integer> equalityMap = memberStatEqualityQueryService.getEquality(memberId, | |||
joinedMates.stream().map(mate -> mate.getMember().getId()).collect(Collectors.toList())); | |||
Integer roomEquality = getCalculateRoomEquality(equalityMap); | |||
Integer roomEquality = RoomStatUtil.getCalculateRoomEquality(equalityMap); |
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.
RoomStatUtil 적용 2
@@ -307,7 +300,7 @@ public List<RoomSearchResponseDTO> searchRooms(String keyword, Long memberId) { | |||
); | |||
return RoomConverter.toRoomSearchResponseDTO( | |||
room, | |||
getCalculateRoomEquality(equalityMap) | |||
RoomStatUtil.getCalculateRoomEquality(equalityMap) |
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.
RoomStatUtil 적용 3
@@ -330,7 +323,7 @@ public List<RoomSearchResponseDTO> searchRooms(String keyword, Long memberId) { | |||
); | |||
return RoomConverter.toRoomSearchResponseDTO( | |||
room, | |||
getCalculateRoomEquality(equalityMap) | |||
RoomStatUtil.getCalculateRoomEquality(equalityMap) |
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.
RoomStatUtil 적용 4
Map<Long, List<Mate>> roomMateMap = mateRepository.findAllFetchMemberAndMemberStatByEntryStatus( | ||
EntryStatus.JOINED) |
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.
여기도 페치조인 적용했어요
List<PreferenceMatchCountDTO> preferenceStatsMatchCounts = RoomStatUtil.getPreferenceStatsMatchCounts( | ||
member, preferenceList, roomMateMap.get(room.getId()), member.getMemberStat()); |
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.
RoomStatUtil 사용으로 변경했습니다
List<PreferenceMatchCountDTO> preferenceMatchCountDTOList = RoomStatUtil.getPreferenceStatsMatchCountsWithoutMemberStat( | ||
memberPreferenceList); |
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.
RoomStatUtil 사용으로 변경했습니다2
리뷰해드려요~FavoriteQueryService.java - Review 1
private List<PreferenceMatchCountDTO> getPreferenceStatsMatchCounts(Member member,
List<String> criteriaPreferenceList, List<Mate> mates, MemberStat memberStat) {
// 선호 스탯 일치 횟수 계산
List<PreferenceMatchCountDTO> preferenceMatchCountDTOList = criteriaPreferenceList.stream()
.map(preference -> {
long equalCount = mates.stream()
.map(mate -> mate.getMember().getMemberStat())
.filter(mateStat -> mateStat != null && !mateStat.getMember().getId().equals(
member.getId())
&& Objects.equals(MemberStatUtil.getMemberStatField(mateStat, preference),
MemberStatUtil.getMemberStatField(memberStat, preference)))
.count();
return PreferenceMatchCountDTO.builder()
.preferenceName(preference)
.count((int) equalCount)
.build();
}).toList();
return preferenceMatchCountDTOList;
}
private List<PreferenceMatchCountDTO> getPreferenceStatsMatchCounts(Member member,
List<String> criteriaPreferenceList, List<Mate> mates, MemberStat memberStat) {
return RoomStatUtil.getPreferenceStatsMatchCounts(member, criteriaPreferenceList, mates, memberStat);
} MateRepository.java - Review 2
RoomRecommendConverter.java - Review 3
RoomRecommendationResponseDTO.java - Review 4
RoomQueryService.java - Review 5
private Integer getCalculateRoomEquality(Map<Long, Integer> equalityMap){
List<Integer> roomEquality = equalityMap.values().stream()
.toList();
int sum = roomEquality.stream().mapToInt(Integer::intValue).sum();
return roomEquality.isEmpty() ? null : sum / roomEquality.size();
}
private Integer getCalculateRoomEquality(Map<Long, Integer> equalityMap){
return RoomStatUtil.getCalculateRoomEquality(equalityMap);
} RoomRecommendService.java - Review 6
private Map<Long, Integer> calculateRoomEqualityMap(List<Room> roomList, Member member,
Map<Long, List<Mate>> roomMateMap) {
// 코드 생략
}
private HashMap<Long, Integer> calculateRoomEqualityMap(List<Room> roomList, Member member,
Map<Long, List<Mate>> roomMateMap) {
// 코드 생략
} RoomStatUtil.java - Review 7
추가 개선 사항:
|
리뷰해드려요~
These changes aim to improve the performance of the application by reducing the number of database queries and improving the readability of the code. The new methods |
리뷰해드려요~FavoriteQueryService.java - Review
MateRepository.java - Review
RoomRecommendConverter.java - Review
RoomRecommendationResponseDTO.java - Review
RoomQueryService.java - Review
RoomRecommendService.java - Review
RoomStatUtil.java - Review
These changes aim to refactor the codebase by moving duplicated logic to a utility class and simplifying the code by removing unnecessary imports and dependencies. |
List<Mate> mates = roomMateMap.get(room.getId()); | ||
|
||
Map<Long, Integer> equalityMap = memberStatEqualityQueryService.getEquality( | ||
member.getId(), | ||
mates.stream() | ||
.map(mate -> mate.getMember().getId()) | ||
.toList() | ||
); | ||
|
||
Integer roomEquality = RoomStatUtil.getCalculateRoomEquality(equalityMap); | ||
|
||
roomEqualityMap.put(room.getId(), roomEquality); |
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.
LGTM~ join fetch 적용도 좋은 것 같슴당
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.
LGTM입니다.
열심히 작성한 방 추천 코드는 다시 만들어졌군요... ㅠㅜ
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.
global Util말고 room util로 넣어주세요
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.
이 파일은 Global보다 room에 직접적인 연관이 있는 유틸이니 Room 패키지에 util로 들어가는게 맞다고 봅니당
global은 어떤 도메인과 연관을 가지지 않는 클래스를 놓는거라고 생각해서요
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.
넵 수정했습니다
리뷰해드려요~FavoriteQueryService.java - Review 1
MateRepository.java - Review 1
RoomRecommendConverter.java - Review 1
RoomRecommendationResponseDTO.java - Review 1
RoomQueryService.java - Review 1
RoomRecommendService.java - Review 1
RoomStatUtil.java - Review 1
In conclusion, the changes are focused on refactoring and optimizing the code related to room statistics and preferences. The |
⚒️develop의 최신 커밋을 pull 받았나요?
#️⃣ 작업 내용
동작 확인
수정 전 방 추천 조회
수정 후 방 추천 조회 - 칩 일치수 반환 형태가 좀 수정되었습니다
찜한 방 조회
RoomQueryService에서 4개? RoomStatUtil로 변경되었는데 그 중 한개 테스트
일치율 잘 나옵니다
💬 리뷰 요구사항(선택)
@eple0329 @suuu0719 두 분 코드 조금 수정해서 확인해주세요~