Compare commits

...

2 Commits

Author SHA1 Message Date
0aaa29b1e2 Tidies up the startup code to make it more readable
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-07-01 21:23:57 -05:00
3e2f0ca681 Adds more logging statements to the album cache service 2024-07-01 21:23:13 -05:00
2 changed files with 15 additions and 13 deletions

View File

@ -32,6 +32,7 @@ class AlbumCacheService(
it.isFile && it.extension == "mp3" && it.name.startsWith("01.")
}
.toList()
logger.info { "Album count: ${fileList.count()}" }
when (type) {
CacheType.ART -> cacheArt(fileList)
CacheType.NEW -> cacheNew(fileList)
@ -40,6 +41,7 @@ class AlbumCacheService(
}
suspend fun cacheAll(fileList: List<File>) {
logger.debug { "Caching all albums..." }
fileList.forEach {
val mp3File = Mp3File(it)
val folderPath = it.parentFile.toPath()
@ -57,9 +59,11 @@ class AlbumCacheService(
)
)
}
logger.debug { "...completed caching all albums." }
}
suspend fun cacheNew(fileList: List<File>) {
logger.debug { "Caching new albums..." }
fileList.forEach {
val folderPath = it.parentFile.toPath()
val folderHash = folderPath.name.hashCode().toString()
@ -79,9 +83,11 @@ class AlbumCacheService(
)
}
}
logger.debug { "...completed caching new albums." }
}
suspend fun cacheArt(fileList: List<File>) {
logger.debug { "Caching album art..." }
fileList.forEach {
val folderPath = it.parentFile.toPath()
val folderHash = folderPath.name.hashCode().toString()
@ -89,6 +95,7 @@ class AlbumCacheService(
launch { getAndWriteAlbumImageFile(it, folderHash, folderPath) }
}
}
logger.debug { "...completed caching album art." }
}
fun createAlbumArtRootDir() {

View File

@ -21,19 +21,14 @@ class StartupService(
@Async
@EventListener(ApplicationStartedEvent::class)
suspend fun onStartup() {
if (withContext(ioDispatcher) {
albumRepository.count()
} == 0L) {
val cacheType = if (withContext(ioDispatcher) { albumRepository.count() } == 0L) {
CacheType.ALL}
else {
CacheType.NEW
}
coroutineScope {
launch {
albumCacheService.cacheAlbums(CacheType.ALL)
}
}
} else {
coroutineScope {
launch {
albumCacheService.cacheAlbums(CacheType.NEW)
}
albumCacheService.cacheAlbums(cacheType)
}
}
}