-
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
[Fix/meal create] 식사 도메인 내 API 수정 #46
Conversation
service와 repository 내부 함수 실행 시점부터 종료시점까지의 소요 시간을 측정해서 콘솔창에 남깁니다.
- 피그마 상에 노출되어야 하는 데이터에 맞추어 DTO를 수정했습니다. - 등록 시, 동일한 제공일자와 식사구분 데이테를 갖고 있는지 검증 로직으로 변경했습니다. - 학식 하루/주간 조회 성능 고도화를 위해 비동기 처리/인덱스/Instant 타입 변경을 수행하였습니다.
조회 로직 고도화 과정을 기록합니다.1. '등록되지 않은 식단입니다.' 출력을 위한 7일 간의 아침/점심/저녁 조회 쿼리 각각 수행학식조회 ( 주간 )
2. 제공일자, 학생식당, 식사구분에 인덱스 설정3. 제공일자의 타입을 LocalDate -> Instant로 변경4. 1번의 쿼리 수행을 비동기 방식으로 처리5. 응답 데이터로 변환 과정 코드 간소화 |
@Qbeom0925 이 PR이 merge 되면, 피그마 기반 연관 엔티티와 속성 정의 작업 이어서 하겠습니다~! |
최대는 첫번째에 호출한 결과이구 최소는 두번째 호출한 결과일까요? |
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.
튜닝 완료하였습니다.
첫번째 호출 (JPA 영속성 컨텍스트에 값 미존재 DB 연결)
평균 150ms
두번째 호출 (JPA 영속성 컨텍스트에 값 존재)
평균 10ms대 유지
변경점
- 쿼리 효율화: 새로운 코드에서는 주어진 식당 및 기간 내의 식단 데이터를 한 번의 쿼리로 효율적으로 가져왔습니다. 이것은 여러 비동기 쿼리를 조합하는 대신 데이터베이스에서 필요한 정보를 한 번에 가져옴으로써 성능 향상을 이루었습니다.
- 성능 향상: 전반적으로 성능이 향상되었으며, 약 100ms 이상의 시간을 절약했습니다.
- 비동기 쿼리를 개선: 이전 코드에서는 여러 비동기 CompletableFuture를 사용하여 데이터를 검색하고 조합했습니다. 새로운 코드에서는 JPA QueryDSL의 메서드를 사용하여 데이터를 효율적으로 검색했습니다.
- QueryDSL에서 transform을 사용하여 DTO 기반 조회 및 그룹핑을 진행했습니다
결과 쿼리를 총 2개의 쿼리문으로 줄였습니다.
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.
코드에서 중요한 부분들 집었습니다!
.orderBy(QMeal.meal.offeredAt.desc(), QMeal.meal.mealType.desc()) | ||
.fetch(); | ||
return queryResult; | ||
public List<WeekMealListGetResTest> getWeekMealList(Restaurant restaurant, Instant mondayInstant, |
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.
쿼리 확인했습니다!
이렇게 줄어들 수 있다니 신기해요!
@@ -101,13 +102,14 @@ public ApplicationResponse<List<DayMealListGetRes>> getDayMeal( | |||
*/ | |||
@GetMapping("/week") | |||
@Operation(summary = "주간 식단 조회") | |||
public ApplicationResponse<List<WeekMealListGetRes>> getWeekMeal( | |||
public ApplicationResponse<List<WeekMealListGetResTest>> getWeekMeal( |
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.
일단 DTO 구분으로 Test로 만들어 두었습니다.
은비님이 이어서 세부 조건문 추가하여 사용해보세요!!
|
||
private String menu; | ||
private MealType mealType; | ||
private MealStatus mealStatus; |
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.
일단 급한대루 Enum을 그대로 조회하였습니다. 이 부분도 튜닝하면 가능하나, 필요성은 느끼지 못하여 repository 단계에서는 하지 않았습니다.
- 등록되지 않은 데이터 포맷에 맞추어 반환 작업을 서비스 레이어에서 레포지토리 레이어로 변경하였습니다.
…reate # Conflicts: # src/main/java/everymeal/server/meal/service/MealServiceImpl.java
Kudos, SonarCloud Quality Gate passed! |
@Qbeom0925 규범님, 당일/주간 식단 조회 쿼리 튜닝 작업 진행했습니다!@ 가이드로 작성해주신 코드 기반으로 기존 코드 리펙토링 했습니다. |
작업 내용
식사 도메인 내 API 수정을 하였습니다.
기존 ) 제공일자 (offeredAt)을 기준으로, 덮어쓰기 방지 검증
변경 ) 제공일자 & 학식구분( mealType ) 기준으로, 덮어쓰기 방지 검증
기존 ) 등록되어 있는 데이터만 리스트화 해서 반환
변경 ) 등록되어 있지 않은 데이터 확인 후, 아침/점심/저녁 포멧으로 더미 데이터로 바인딩하여 리스트화 해서 반환
관련 이슈
#44
작업 확인 방법
주간단위 식사 조회 API 수행 시, 테스트 응답 데이터
추가 정보 (선택 사항)
수행시간 측정 범위가 넓다고 생각되면, Service 혹은 Repository 범위는 LogAspect 파일에서 수정가능합니다.