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

플레이리스트 정보에 음악 개수, 썸네일 링크 추가 #221

Merged
merged 5 commits into from
Nov 29, 2023

Conversation

khw3754
Copy link
Collaborator

@khw3754 khw3754 commented Nov 28, 2023

Issue

Overview

  • 플레이리스트 API 응답에 음악 개수, 썸네일 링크를 추가했습니다.

  • playlist id 로 음악의 개수, 썸네일을 반환하는 함수들을 추가하여 처리했습니다.
  • 특성상 쿼리문이 많이 발생하게 되어서 Promise.all 로 병렬 처리를 시켜서 시간을 단축시켰습니다.

Screenshot

  • 테스트 (11ms)
image

To Reviewers

참고자료 - [JS] forEach 함수는 async 함수를 기다려주지 않는다

쿼리문들을 병렬 처리시켜서 시간을 단축하기는 했지만, 쿼리문이 많이 발생하는 것이 사실이라 근본적으로 줄일 수 있다면 줄이는 것이 좋아 보입니다.

* musicinfo API 에서 500 으로 되어있는 오타 200 으로 수정
* playlist_id 로 음악의 개수를 받는 entity 쿼리문 추가
* getMusicCountByPlaylistId 와 Promise.all을 사용해서 음악 개수 추가
* playlistId 로 썸네일을 반환하는 함수
* id 가 가장 큰 (= 플레이리스트에 가장 최근에 추가한) 노래의 cover 반환
* getThumbnailByPlaylistId 를 활용하여 썸네일 정보 추가
@khw3754 khw3754 added 🛠️ refactor 리팩토링 🖥 server server labels Nov 28, 2023
@khw3754 khw3754 added this to the ⏯️ playlist milestone Nov 28, 2023
@khw3754 khw3754 self-assigned this Nov 28, 2023
@khw3754 khw3754 requested a review from sk000801 as a code owner November 28, 2023 17:41
@khw3754 khw3754 linked an issue Nov 28, 2023 that may be closed by this pull request
Copy link
Member

@sk000801 sk000801 left a comment

Choose a reason for hiding this comment

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

단연코 typeorm의 고수 👍
시간 단축 결과가 야무져 보이네용 (11ms는 신기하네요)

Comment on lines +85 to 95
static async getThumbnailByPlaylistId(
playlist_id: number,
): Promise<Music_Playlist> {
return this.findOne({
relations: { music: true },
select: { music: { cover: true } },
where: { playlist: { playlist_id } },
order: { music_playlist_id: 'DESC' },
});
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 하나씩 떼어서 가져와야 하는 군요 ㅠㅠㅠ 고생하셨어요 👍😊🙇‍♀️
typeorm 쿼리문(?)들은 항상 제가 배워가는 것 같네요

Comment on lines +180 to +181
await Promise.all(countPromises);
await Promise.all(thumbnailPromises);
Copy link
Member

Choose a reason for hiding this comment

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

한번에 묶어서 처리하신게 좋아보입니다!! 👍😊
각각의 플레이리스트마다 모두 썸네일이랑 음악 개수를 순차적으로 넣어줘야 해서 Promise.all를 쓰신거죠 ?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

각각 플레이리스트마다 쿼리문이 발생하는데, 그 쿼리문들을 for 문으로 모두 동기적으로 처리하면 시간이 오래 걸리니까 Promise.all 로 비동기적으로 병렬 처리를 했습니다!

@khw3754 khw3754 merged commit 128cee5 into develop Nov 29, 2023
@khw3754 khw3754 deleted the server/refactor/215 branch November 29, 2023 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

플레이리스트 가져오는 API 반환값 추가
2 participants