Open
Conversation
… simultaneously fetch multiple bags' error for PlaylistServiceTest 플레이리스트 조회
Member
|
과제 너무 잘해주셨네요~ 많이 고민해주신게 느껴졌습니다! |
PFCJeong
approved these changes
Oct 1, 2023
| override fun getGroups(): List<PlaylistGroup> { | ||
| TODO() | ||
| val playlistGroupEntityList = playlistGroupRepository.findNonEmptyGroupsByOpen(true) | ||
| return playlistGroupEntityList.map { |
Member
There was a problem hiding this comment.
playlistGroupEntityList.map(::PlaylistGroup) 이렇게 해줘도 괜찮을 거 같습니다.
| JOIN FETCH s.album ab | ||
| WHERE p.id = :id | ||
| """) | ||
| fun findByIdWithSongs(id: Long): PlaylistEntity? |
Member
There was a problem hiding this comment.
Set을 사용해서 N:N, 1:N에서 MultipleBagException을 피하신 걸로 보입니다. 굿 👍
이 케이스(곡, 아티스트라는 도메인)에서는 퍼포먼스 이슈가 없을 것 같은데요. 특정 상황에서 심각한 성능 이슈가 생길 수도 있기 때문에 싱글 쿼리를 포기하고, 쿼리를 나누기도 합니다.
| throw PlaylistNotFoundException() | ||
| } | ||
| // findByIdWithUsers() return empty list if there is no user-likes-playlist relationship (INNER JOIN) | ||
| val playlistEntity = playlistRepository.findByIdWithUsers(playlistId) ?: return false |
Member
There was a problem hiding this comment.
플레이리스트에 눌린 좋아요가 많을 때 조회되는 row들이 많아질 수 있을 것 같습니다.
play_list_likes 테이블을 playlist_id, user_id로 조회하는 방법이 더 바람직해보입니다. (최대 row 1)
| } | ||
| val playlistEntity = playlistRepository.findById(playlistId).getOrElse { throw PlaylistNotFoundException() } | ||
| val userEntity = userRepository.findById(userId).getOrElse { throw RuntimeException("User Not Found") } | ||
| playlistLikesRepository.save(PlaylistLikesEntity(1L, playlistEntity, userEntity)) |
| throw PlaylistNeverLikedException() | ||
| } | ||
| val playlistEntity = playlistRepository.findById(playlistId).getOrElse { throw PlaylistNotFoundException() } | ||
| val likeRecord = playlistLikesRepository.findByPlaylist(playlistEntity) |
Member
There was a problem hiding this comment.
이것도 마찬가지로 play_list_likes 테이블을 playlist_id, user_id로 조회하는 방법이 좋을 것 같습니다.
|
|
||
| @Transactional | ||
| @SpringBootTest | ||
| class PlaylistServiceCacheTest @Autowired constructor( |
| import java.util.concurrent.ScheduledFuture | ||
|
|
||
| @Component | ||
| class CacheTTLImpl ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.