Skip to content

Commit

Permalink
refactor: 즐겨찾기 N+1 문제해결
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed Sep 19, 2024
1 parent 1d04b51 commit 824820c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface GroupFavoriteRepository extends JpaRepository<GroupFavorite, Lo
@Transactional
@Query("DELETE FROM GroupFavorite gf WHERE gf.user.id = :userId AND gf.groupRoom.groupCode = :groupCode")
void deleteByUserIdAndGroupRoomId(@Param("userId") Long userId, @Param("groupCode") String groupCode);

@Query("SELECT gf FROM GroupFavorite gf JOIN FETCH gf.groupRoom WHERE gf.user.id = :userId")
List<GroupFavorite> findFavoriteGroupsByUser(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class GroupFavoriteService {
private final UserQueryService userQueryService;
private final GroupQueryService groupQueryService;


@Transactional(readOnly = true)
public List<GroupResponse> findFavoriteGroupsByUser(UserInfo userInfo) {
return userQueryService.getUserByUserCode(userInfo.getUserCode())
.getGroupFavorites()
return groupFavoriteRepository.findFavoriteGroupsByUser(userInfo.getId())
.stream()
.map(GroupFavorite::getGroupRoom)
.map(GroupResponse::from)
Expand Down

0 comments on commit 824820c

Please sign in to comment.