Skip to content

Commit

Permalink
Merge pull request #452 from Team-Ampersand/451-hotfix/music-delete-s…
Browse files Browse the repository at this point in the history
…chedule

451 hotfix 음악 삭제 스케쥴 플로우 조정
  • Loading branch information
esperar committed Sep 30, 2024
2 parents e094111 + e0c9ef6 commit f52f950
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ interface MusicLikeRepository : JpaRepository<MusicLike,Long> {

fun deleteAllByMusicId(music: Long)

fun deleteAllByMusicIdIn(musicIds: List<Long>)

fun existsByMusicIdAndMemberId(musicId: Long, memberId: Long): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface MusicRepository : JpaRepository<Music, Long> {

fun deleteAllByCreatedDateBefore(date: LocalDateTime)

fun findAllByCreatedDateBefore(date: LocalDateTime): List<Music>

@Query(value = "select * from music where created_date like :date% order by music.like_count desc", nativeQuery = true)
fun findAllByCreatedDateOrderByLikeCountDESC(@Param("date") date: LocalDate): List<Music>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotori.v2.domain.music.schedule

import com.dotori.v2.domain.music.domain.repository.MusicLikeRepository
import com.dotori.v2.domain.music.domain.repository.MusicRepository
import com.dotori.v2.global.config.redis.service.RedisCacheService
import org.slf4j.LoggerFactory
Expand All @@ -15,6 +16,7 @@ import java.time.temporal.ChronoUnit
@Transactional
class MusicSchedule(
private val musicRepository: MusicRepository,
private val musicLikeRepository: MusicLikeRepository,
private val redisCacheService: RedisCacheService
) {
private val log = LoggerFactory.getLogger(this.javaClass.simpleName)
Expand All @@ -27,7 +29,9 @@ class MusicSchedule(
@Scheduled(cron = "0 0 0 1 * ?")
fun initMusic() {
val localDateTime = LocalDateTime.now().minus(2, ChronoUnit.MONTHS)
musicRepository.deleteAllByCreatedDateBefore(localDateTime)
val musics = musicRepository.findAllByCreatedDateBefore(localDateTime)
musicLikeRepository.deleteAllByMusicIdIn(musics.map { it.id })
musicRepository.deleteAllInBatch(musics)
redisCacheService.initCache("musicList:*")
log.info("delete music data schedule")
}
Expand Down

0 comments on commit f52f950

Please sign in to comment.