-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
학교 정보 조회와 포인트 정보 조회는 서로 의존성이 없는 네트워크 호출이므로, CompletableFuture를 사용하여 병렬로 처리하면 API 응답 시간을 단축할 수 있습니다. 현재는 순차적으로 실행되어 불필요한 대기 시간이 발생합니다.
다음과 같이 수정할 수 있습니다:
// ...
final MemberInfoResult result = memberQueryService.getInfo(memberPrincipal.memberId());
// I/O-bound 작업을 위한 별도의 Executor를 주입받아 사용하는 것이 좋습니다.
// private final Executor ioExecutor;
CompletableFuture<SchoolInfo> schoolInfoFuture = CompletableFuture.supplyAsync(() ->
schoolClient.getSchool(RequestType.JSON.getType(), result.schoolCode())
.orElse(SchoolInfo.none()), ioExecutor);
CompletableFuture<PointInfo> pointInfoFuture = CompletableFuture.supplyAsync(() ->
pointClient.getRemainPoint(memberPrincipal.memberId()), ioExecutor);
CompletableFuture.allOf(schoolInfoFuture, pointInfoFuture).join();
final SchoolInfo schoolInfo = schoolInfoFuture.get();
final PointInfo pointInfo = pointInfoFuture.get();
return ResponseEntity.ok(Responses.MemberInfoDetailResponse.from(result, schoolInfo, pointInfo));이렇게 변경하면 두 외부 호출을 동시에 실행하여 전체 대기 시간을 줄일 수 있습니다.
Originally posted by @gemini-code-assist[bot] in #227 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels