-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
* musicinfo API 에서 500 으로 되어있는 오타 200 으로 수정
* playlist_id 로 음악의 개수를 받는 entity 쿼리문 추가
* getMusicCountByPlaylistId 와 Promise.all을 사용해서 음악 개수 추가
* playlistId 로 썸네일을 반환하는 함수 * id 가 가장 큰 (= 플레이리스트에 가장 최근에 추가한) 노래의 cover 반환
* getThumbnailByPlaylistId 를 활용하여 썸네일 정보 추가
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.
단연코 typeorm의 고수 👍
시간 단축 결과가 야무져 보이네용 (11ms는 신기하네요)
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' }, | ||
}); | ||
} | ||
} |
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.
이렇게 하나씩 떼어서 가져와야 하는 군요 ㅠㅠㅠ 고생하셨어요 👍😊🙇♀️
typeorm 쿼리문(?)들은 항상 제가 배워가는 것 같네요
await Promise.all(countPromises); | ||
await Promise.all(thumbnailPromises); |
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.
한번에 묶어서 처리하신게 좋아보입니다!! 👍😊
각각의 플레이리스트마다 모두 썸네일이랑 음악 개수를 순차적으로 넣어줘야 해서 Promise.all
를 쓰신거죠 ?!
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.
각각 플레이리스트마다 쿼리문이 발생하는데, 그 쿼리문들을 for 문으로 모두 동기적으로 처리하면 시간이 오래 걸리니까 Promise.all 로 비동기적으로 병렬 처리를 했습니다!
Issue
Overview
Screenshot
To Reviewers
참고자료 - [JS] forEach 함수는 async 함수를 기다려주지 않는다
쿼리문들을 병렬 처리시켜서 시간을 단축하기는 했지만, 쿼리문이 많이 발생하는 것이 사실이라 근본적으로 줄일 수 있다면 줄이는 것이 좋아 보입니다.