Skip to content

Commit

Permalink
Merge pull request #228 from ASAP-as-soon-as-possible/feat/#227
Browse files Browse the repository at this point in the history
#227 [feat] [feat] 로그인 시 발생하는 N+1 이슈 해결 및 기타 작업
  • Loading branch information
KWY0218 authored Oct 11, 2023
2 parents ede8459 + e0b077e commit b965b21
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/asap/server/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class UserController {
@Operation(summary = "[회의 가능 시간 입력 뷰 - 방장] 방장 가능 시간 입력 API")
@SecurityRequirement(name = "JWT Auth")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "방장의 회의 가능 시간이 성공적으로 입력되었습니다."),
@ApiResponse(responseCode = "201", description = "방장의 회의 가능 시간이 성공적으로 입력되었습니다."),
@ApiResponse(responseCode = "400",
description = "1. 시간 형식이 잘못되었습니다. [YYYY/MM/DD HH:MM]\n"
+ "2. 중복 입력된 시간이 있습니다.\n"
Expand All @@ -70,7 +70,7 @@ public SuccessResponse<UserMeetingTimeResponseDto> createHostTime(

@Operation(summary = "[회의 가능 시간 입력 뷰 - 참여자] 참여자 정보 및 가능 시간 입력 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "참여자 회의 가능 시간 입력을 성공하였습니다."),
@ApiResponse(responseCode = "201", description = "참여자 회의 가능 시간 입력을 성공하였습니다."),
@ApiResponse(responseCode = "400",
description = "1. 시간 형식이 잘못되었습니다. [YYYY/MM/DD HH:MM]\n"
+ "2. 중복 입력된 시간이 있습니다.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.asap.server.domain.AvailableDate;
import com.asap.server.domain.Meeting;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -17,8 +14,4 @@ public interface AvailableDateRepository extends Repository<AvailableDate, Long>
List<AvailableDate> findByMeeting(final Meeting meeting);

Optional<AvailableDate> findByMeetingAndDate(final Meeting meeting, final LocalDate date);

@Modifying(clearAutomatically = true)
@Query("delete from AvailableDate a where a.meeting = :meeting")
void deleteByMeeting(@Param("meeting") final Meeting meeting);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.asap.server.repository;

import com.asap.server.domain.Meeting;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface MeetingRepository extends Repository<Meeting, Long> {
Optional<Meeting> findById(final Long id);

Meeting save(final Meeting meeting);

void saveAndFlush(final Meeting meeting);

@EntityGraph(attributePaths = {"host"})
@Query("select m from Meeting m where m.id = :id")
Optional<Meeting> findByIdWithHost(@Param("id") final Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.asap.server.domain.Meeting;
import com.asap.server.domain.PreferTime;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;

Expand All @@ -14,9 +11,4 @@ public interface PreferTimeRepository extends Repository<PreferTime, Long> {
PreferTime save(final PreferTime preferTime);

List<PreferTime> findByMeeting(final Meeting meeting);


@Modifying(clearAutomatically = true)
@Query("delete from PreferTime p where p.meeting = :meeting")
void deleteByMeeting(@Param("meeting") final Meeting meeting);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.asap.server.domain.AvailableDate;
import com.asap.server.domain.TimeBlock;
import com.asap.server.domain.enums.TimeSlot;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;
Expand All @@ -18,10 +15,4 @@ public interface TimeBlockRepository extends Repository<TimeBlock, Long> {
List<TimeBlock> findByAvailableDate(final AvailableDate availableDate);

Optional<TimeBlock> findByAvailableDateAndTimeSlot(final AvailableDate availableDate, TimeSlot timeSlot);

List<TimeBlock> findByAvailableDateIn(final List<AvailableDate> availableDates);

@Modifying(clearAutomatically = true)
@Query("delete from TimeBlock t where t.availableDate in :availableDates")
void deleteByAvailableDatesIn(@Param("availableDates") final List<AvailableDate> availableDates);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ public interface TimeBlockUserRepository extends Repository<TimeBlockUser, Long>
List<TimeBlockUser> findAllByUser(final User user);

List<TimeBlockUser> findByTimeBlock(final TimeBlock timeBlock);

@Modifying(clearAutomatically = true)
@Query("delete from TimeBlockUser t where t.timeBlock in :timeblocks")
void deleteByTimeBlocksIn(@Param("timeblocks") final List<TimeBlock> timeBlocks);
}
10 changes: 0 additions & 10 deletions src/main/java/com/asap/server/service/AvailableDateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.asap.server.controller.dto.response.TimeSlotDto;
import com.asap.server.domain.AvailableDate;
import com.asap.server.domain.Meeting;
import com.asap.server.domain.TimeBlock;
import com.asap.server.exception.Error;
import com.asap.server.exception.model.BadRequestException;
import com.asap.server.exception.model.NotFoundException;
Expand Down Expand Up @@ -115,13 +114,4 @@ public void create(final Meeting meeting, final List<String> availableDates) {
private boolean isDuplicatedDate(final List<String> availableDates) {
return availableDates.size() != availableDates.stream().distinct().count();
}

public void deleteUserTimes(final Meeting meeting) {
List<AvailableDate> availableDates = availableDateRepository.findByMeeting(meeting);
List<TimeBlock> timeBlocks = timeBlockService.findByAvailableDateIn(availableDates);

timeBlockUserService.deleteTimeBlockUsers(timeBlocks);
timeBlockService.deleteTimeBlocks(availableDates);
availableDateRepository.deleteByMeeting(meeting);
}
}
11 changes: 2 additions & 9 deletions src/main/java/com/asap/server/service/MeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ public void confirmMeeting(
if (!meeting.authenticateHost(userId))
throw new UnauthorizedException(INVALID_MEETING_HOST_EXCEPTION);

userService.setFixedUsers(meeting, meetingConfirmRequestDto.getUsers());

deleteMeetingTimes(meeting);

LocalDate fixedDate = DateUtil.transformLocalDate(meetingConfirmRequestDto.getMonth(), meetingConfirmRequestDto.getDay());
LocalTime startTime = DateUtil.parseLocalTime(meetingConfirmRequestDto.getStartTime().getTime());
LocalTime endTime = DateUtil.parseLocalTime(meetingConfirmRequestDto.getEndTime().getTime());
Expand All @@ -108,12 +104,9 @@ public void confirmMeeting(
LocalDateTime fixedEndDateTime = LocalDateTime.of(fixedDate, endTime);
meeting.setConfirmedDateTime(fixedStartDateTime, fixedEndDateTime);

meetingRepository.save(meeting);
}
meetingRepository.saveAndFlush(meeting);

private void deleteMeetingTimes(final Meeting meeting) {
availableDateService.deleteUserTimes(meeting);
preferTimeService.deletePreferTimes(meeting);
userService.setFixedUsers(meeting, meetingConfirmRequestDto.getUsers());
}

@Transactional(readOnly = true)
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/asap/server/service/PreferTimeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public List<PreferTimeResponseDto> getPreferTimes(final Meeting meeting) {
.collect(Collectors.toList());
}

public void deletePreferTimes(final Meeting meeting) {
preferTimeRepository.deleteByMeeting(meeting);
}

private boolean isPreferTimeDuplicated(List<PreferTimeSaveRequestDto> requestDtos) {
List<TimeSlot> timeSlots = requestDtos.stream()
.flatMap(requestDto -> TimeSlot.getTimeSlots(requestDto.getStartTime().ordinal(), requestDto.getEndTime().ordinal() - 1).stream())
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/asap/server/service/TimeBlockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,4 @@ private TimeBlock create(final TimeSlot timeSlot, final AvailableDate availableD
public List<TimeBlock> getTimeBlocksByAvailableDate(final AvailableDate availableDate) {
return timeBlockRepository.findByAvailableDate(availableDate);
}

public List<TimeBlock> findByAvailableDateIn(final List<AvailableDate> availableDates) {
return timeBlockRepository.findByAvailableDateIn(availableDates);
}

public void deleteTimeBlocks(final List<AvailableDate> availableDates) {
timeBlockRepository.deleteByAvailableDatesIn(availableDates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,4 @@ public boolean isEmptyHostTimeBlock(final User user) {
return hostTimeBlocks.isEmpty();
}

public void deleteTimeBlockUsers(final List<TimeBlock> timeBlocks) {
timeBlockUserRepository.deleteByTimeBlocksIn(timeBlocks);
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/asap/server/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public HostLoginResponseDto loginByHost(
final Long meetingId,
final HostLoginRequestDto requestDto
) {
Meeting meeting = meetingRepository.findById(meetingId)
Meeting meeting = meetingRepository.findByIdWithHost(meetingId)
.orElseThrow(() -> new NotFoundException(Error.MEETING_NOT_FOUND_EXCEPTION));

if (!meeting.checkHostName(requestDto.getName()))
Expand Down

0 comments on commit b965b21

Please sign in to comment.