Skip to content

조성해 seminar1 과제#41

Open
SeonghaeJo wants to merge 10 commits intowafflestudio:master-week1from
SeonghaeJo:master-week1
Open

조성해 seminar1 과제#41
SeonghaeJo wants to merge 10 commits intowafflestudio:master-week1from
SeonghaeJo:master-week1

Conversation

@SeonghaeJo
Copy link

@SeonghaeJo SeonghaeJo commented Sep 30, 2023

  1. many-to-many 관계를 ManyToMany와 JoinTable 어노테이션으로 구현하는 게 나을지, 중간 테이블도 엔티티로 만들고 2개의 one-to-many 관계로 분리하여 구현하는 게 나을지 고민되어 둘 다 시도해봤습니다.
  2. 캐시의 경우 TaskScheduler 빈을 추가하여 구현하였고, PlaylistServiceCacheTest에서 간단한 테스트 수행하였습니다.

@PFCJeong
Copy link
Member

PFCJeong commented Oct 1, 2023

과제 너무 잘해주셨네요~ 많이 고민해주신게 느껴졌습니다!

override fun getGroups(): List<PlaylistGroup> {
TODO()
val playlistGroupEntityList = playlistGroupRepository.findNonEmptyGroupsByOpen(true)
return playlistGroupEntityList.map {
Copy link
Member

Choose a reason for hiding this comment

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

playlistGroupEntityList.map(::PlaylistGroup) 이렇게 해줘도 괜찮을 거 같습니다.

JOIN FETCH s.album ab
WHERE p.id = :id
""")
fun findByIdWithSongs(id: Long): PlaylistEntity?
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

플레이리스트에 눌린 좋아요가 많을 때 조회되는 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))
Copy link
Member

Choose a reason for hiding this comment

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

0으로 넣어주는 것이 맞을 것 같습니다.

throw PlaylistNeverLikedException()
}
val playlistEntity = playlistRepository.findById(playlistId).getOrElse { throw PlaylistNotFoundException() }
val likeRecord = playlistLikesRepository.findByPlaylist(playlistEntity)
Copy link
Member

Choose a reason for hiding this comment

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

이것도 마찬가지로 play_list_likes 테이블을 playlist_id, user_id로 조회하는 방법이 좋을 것 같습니다.


@Transactional
@SpringBootTest
class PlaylistServiceCacheTest @Autowired constructor(
Copy link
Member

Choose a reason for hiding this comment

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

👍

import java.util.concurrent.ScheduledFuture

@Component
class CacheTTLImpl (
Copy link
Member

Choose a reason for hiding this comment

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

오호~

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.

2 participants