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: TMDB를 통해 영화정보를 가져오도록 한다 #24

Merged
merged 26 commits into from
Nov 22, 2023

Conversation

cheolwon1994
Copy link
Contributor

@cheolwon1994 cheolwon1994 commented Nov 16, 2023

SWIT

티켓

고려한 사항

TMDB의 특성상 한 페이지에 최대 20개의 영화밖에 못가져온다. 따라서 첫 호출에 대한 응답으로 totalPages를 받고 이를 바탕으로 for문을 돌려야 한다. 이를 효율적이게 할 수 있는 방법 2가지 중 시간이 조금이라도 더 빠른 병렬을 이용한다
(1) 병렬

List<MovieApiResponse.MovieItem> movieList = response.getItems();
int totalPages = response.getTotalPages();

IntStream.rangeClosed(2, totalPages)
         .parallel()
         .forEach(page -> {
             params.put("page", page);
             MovieApiResponse extraResponse = catcherFeignService.parseService(params, MovieApiResponse.class);
             movieList.addAll(extraResponse.getItems());
         });

소요 시간
병렬처리

(2) 비동기

List<MovieApiResponse.MovieItem> movieList = response.getItems();
int totalPages = response.getTotalPages();

List<CompletableFuture<Void>> futures = new ArrayList<>();

for (int i = 2; i <= totalPages; i++) {
    int page = i;
    CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
        params.put("page", page);
        MovieApiResponse extraResponse = catcherFeignService.parseService(params, MovieApiResponse.class);
        movieList.addAll(extraResponse.getItems());
    });

    futures.add(future);
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();

소요 시간(밑 결과)
비동기 처리

변경 사항

  • MovieController에서 불필요한 API 삭제
  • APIService, Adapter 이용해서 API 통신하도록 설정

TODO

  • Update시 썸네일URL, 개봉일 변경 여부 확인 UpdatedAt 칼럼을 계속 수정해줘야 하기 때문에 무조건 갱신하도록
  • 테스트 코드 작성

Copy link

Unit Test Results

5 tests   4 ✔️  0s ⏱️
4 suites  0 💤
4 files    1

For more details on these failures, see this check.

Results for commit bccc31f.

@cheolwon1994 cheolwon1994 changed the base branch from main to dev November 16, 2023 08:57
Copy link
Member

@inyoung0215 inyoung0215 left a comment

Choose a reason for hiding this comment

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

오오오 제가 고민하던 부분을 딱! 👍

Copy link
Contributor

@dev-khg dev-khg left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@cheolwon1994 cheolwon1994 merged commit b9611f3 into dev Nov 22, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants