Skip to content
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

feat-be: Process 관련 API 쿼리 최적화 #711

Merged
merged 10 commits into from
Sep 25, 2024

Conversation

Chocochip101
Copy link
Member

@Chocochip101 Chocochip101 commented Sep 24, 2024

  • process 관련 API의 쿼리를 줄였습니다.

작업 내용

  • 조회 시, N+1 발생 현상을 dto + projection의 조합으로 해결. evaluation이 몇 개든 총 3개의 쿼리로 처리 가능.
  • 불필요한 findById 제거
  • 조회 테스트에서 N+1을 관측할 수 있게 테스트 더미 추가

참고

관련 이슈

PR 체크리스트

  • 테스트는 모두 통과했나요?
  • 빌드는 성공했나요?
  • 코드 포맷팅을 진행했나요?
  • PR 내부의 예시는 삭제하셨나요?

Copy link
Contributor

1727182982.605089

Copy link
Contributor

1727182983.872449

Copy link
Contributor

📌 Test Coverage Report

Overall Project 77.39% -0.08%
Files changed 97% 🍏

File Coverage
EmailController.java 100% 🍏
ProcessFacade.java 100% 🍏
ProcessService.java 96.34% 🍏
ApplicantService.java 95.48% 🍏
EvaluationService.java 91.14% 🍏
ApplicantCard.java 90.32% -9.68% 🍏
ApplyFormService.java 86.23% 🍏
ExceptionLogger.java 86.14% 🍏
Email.java 59.56% 🍏

@Chocochip101 Chocochip101 changed the title feat-be: process 관련 API 쿼리 최적화 feat-be: Process 관련 API 쿼리 최적화 Sep 25, 2024
@xogns1514 xogns1514 added the backend 백엔드 label Sep 25, 2024
@xogns1514 xogns1514 added this to the 스프린트 5.0 milestone Sep 25, 2024
Copy link
Member

@cutehumanS2 cutehumanS2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와우 고급 SQL 문법 쓰셨네요.
간단한 코멘트 남겼으니 확인 부탁드립니다.

수고 많으셨습니다. 👍

Comment on lines +22 to +24
public ApplicantCardResponse toResponse() {
return new ApplicantCardResponse(id, name, createdAt, isRejected, (int) evaluationCount, averageScore);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다른 response 변환 로직은 facade나 service에 있는데,
이 변환 로직은 여기에 두신 이유가 궁금합니다(단순 궁금).

Copy link
Member Author

@Chocochip101 Chocochip101 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전까지는 facade, service 계층에 dto가 없어서요...? 그리고 controller 패키지에서 도메인을 참조해서요.

@@ -64,6 +64,10 @@ private Process toEvaluateProcess(ProcessCreateRequest request, Dashboard dashbo
return new Process(request.sequence(), request.name(), request.description(), ProcessType.EVALUATE, dashboard);
}

public List<Process> findAllByDashboard(Long dashboardId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public List<Process> findAllByDashboard(Long dashboardId) {
public List<Process> findAllByDashboardId(Long dashboardId) {

Copy link
Member Author

@Chocochip101 Chocochip101 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다형성을 활용하기 위해 메서드명을 같게 했습니다. System.out.printlnString() 안하는 것처럼요.
혹시 어색하게 느껴지시나요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아뇨. ㅎ ㅎ 놓치신 줄 알았습니다.
다형성이 이유라면 수정하지 않아도 될 것 같아요.

Copy link
Contributor

@xogns1514 xogns1514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~~! 덕분에 쿼리가 엄청나게 줄었네요. 쿼리문 사용된 기능 잘 동작하는거 확인했습니다. 변경할 사항 없는거 같아 바로 approve 드려요

assertAll(
() -> assertThat(applicantCard.id()).isEqualTo(applicant.getId()),
() -> assertThat(applicantCard.name()).isEqualTo(applicant.getName()),
() -> assertThat(applicantCard.evaluationCount()).isEqualTo(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
() -> assertThat(applicantCard.evaluationCount()).isEqualTo(0),
() -> assertThat(applicantCard.evaluationCount()).isZero(),

Copy link
Member

@cutehumanS2 cutehumanS2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Chocochip101 Chocochip101 merged commit 517595f into be-705-API_PERFORMANCE_01 Sep 25, 2024
5 checks passed
@Chocochip101 Chocochip101 deleted the be-705-API_PERFORMANCE_01_07 branch September 25, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend 백엔드
Projects
Status: 완료
Development

Successfully merging this pull request may close these issues.

3 participants