-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,20 @@ export class PlaylistService { | |
|
||
async getUserPlaylists(userId: string): Promise<Playlist[]> { | ||
try { | ||
return Playlist.getPlaylistsByUserId(userId); | ||
const playlists: Playlist[] = await Playlist.getPlaylistsByUserId(userId); | ||
const countPromises = playlists.map(async (playlist) => { | ||
playlist['music_count'] = | ||
await Music_Playlist.getMusicCountByPlaylistId(playlist.playlist_id); | ||
}); | ||
const thumbnailPromises = playlists.map(async (playlist) => { | ||
const target = await Music_Playlist.getThumbnailByPlaylistId( | ||
playlist.playlist_id, | ||
); | ||
playlist['thumbnail'] = !target ? null : target.music.cover; | ||
}); | ||
await Promise.all(countPromises); | ||
await Promise.all(thumbnailPromises); | ||
Comment on lines
+180
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 각각 플레이리스트마다 쿼리문이 발생하는데, 그 쿼리문들을 for 문으로 모두 동기적으로 처리하면 시간이 오래 걸리니까 Promise.all 로 비동기적으로 병렬 처리를 했습니다! |
||
return playlists; | ||
} catch { | ||
throw new CatchyException( | ||
'SERVER_ERROR', | ||
|
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 쿼리문(?)들은 항상 제가 배워가는 것 같네요