Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public interface PublicCourseRepository extends JpaRepository<PublicCourse, Lon

List<PublicCourse> findByIdIn(Collection<Long> ids);

// deletePublicCourses에서 course/runnectUser(권한 검증)와 records(FK 해제)를 전부 순회하며
// 지연로딩을 트리거하던 N+1을 없애기 위한 전용 조회 (PublicCourseServiceTest 참고)
@Query("SELECT DISTINCT pc FROM PublicCourse pc " +
"JOIN FETCH pc.course c " +
"JOIN FETCH c.runnectUser " +
"LEFT JOIN FETCH pc.records " +
"WHERE pc.id IN :ids")
List<PublicCourse> findByIdInWithCourseAndRecords(@Param("ids") Collection<Long> ids);

Long countBy();

@Query("SELECT pc " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public DeletePublicCoursesResponseDto deletePublicCourses(
.orElseThrow(() -> new NotFoundUserException(ErrorStatus.NOT_FOUND_USER_EXCEPTION,
ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));

List<PublicCourse> publicCourses = publicCourseRepository.findByIdIn(
List<PublicCourse> publicCourses = publicCourseRepository.findByIdInWithCourseAndRecords(
requestDto.getPublicCourseIdList());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class DeletePublicCourses {
PublicCourse publicCourse = buildPublicCourse(100L, course);

when(userRepository.findById(1L)).thenReturn(Optional.of(user));
when(publicCourseRepository.findByIdIn(Collections.singletonList(100L))).thenReturn(
when(publicCourseRepository.findByIdInWithCourseAndRecords(Collections.singletonList(100L))).thenReturn(
Collections.singletonList(publicCourse));

DeletePublicCoursesResponseDto response = publicCourseService.deletePublicCourses(1L,
Expand All @@ -600,7 +600,7 @@ class DeletePublicCourses {
void 존재하지_않는_공개코스_포함() {
RunnectUser user = buildUser(1L);
when(userRepository.findById(1L)).thenReturn(Optional.of(user));
when(publicCourseRepository.findByIdIn(Arrays.asList(100L, 999L))).thenReturn(Collections.emptyList());
when(publicCourseRepository.findByIdInWithCourseAndRecords(Arrays.asList(100L, 999L))).thenReturn(Collections.emptyList());

assertThatThrownBy(() -> publicCourseService.deletePublicCourses(1L,
new DeletePublicCoursesRequestDto(Arrays.asList(100L, 999L))))
Expand All @@ -618,7 +618,7 @@ class DeletePublicCourses {
PublicCourse othersPublicCourse = buildPublicCourse(101L, buildCourse(11L, otherUser, false));

when(userRepository.findById(1L)).thenReturn(Optional.of(user));
when(publicCourseRepository.findByIdIn(Arrays.asList(100L, 101L))).thenReturn(
when(publicCourseRepository.findByIdInWithCourseAndRecords(Arrays.asList(100L, 101L))).thenReturn(
Arrays.asList(ownPublicCourse, othersPublicCourse));

assertThatThrownBy(() -> publicCourseService.deletePublicCourses(1L,
Expand All @@ -637,7 +637,7 @@ class DeletePublicCourses {
PublicCourse othersPublicCourse = buildPublicCourse(101L, buildCourse(11L, otherUser, false));

when(userRepository.findById(adminId)).thenReturn(Optional.of(admin));
when(publicCourseRepository.findByIdIn(Collections.singletonList(101L))).thenReturn(
when(publicCourseRepository.findByIdInWithCourseAndRecords(Collections.singletonList(101L))).thenReturn(
Collections.singletonList(othersPublicCourse));

DeletePublicCoursesResponseDto response = publicCourseService.deletePublicCourses(adminId,
Expand Down
Loading