From 0aaa29b1e2ed5e49c6c025e6b9e71dc40e0904a4 Mon Sep 17 00:00:00 2001 From: aarbit Date: Mon, 1 Jul 2024 21:23:57 -0500 Subject: [PATCH] Tidies up the startup code to make it more readable --- .../prettyplayerapi/service/StartupService.kt | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/service/StartupService.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/service/StartupService.kt index 964e17b..698cf14 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/service/StartupService.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/service/StartupService.kt @@ -21,19 +21,14 @@ class StartupService( @Async @EventListener(ApplicationStartedEvent::class) suspend fun onStartup() { - if (withContext(ioDispatcher) { - albumRepository.count() - } == 0L) { - coroutineScope { - launch { - albumCacheService.cacheAlbums(CacheType.ALL) - } - } - } else { - coroutineScope { - launch { - albumCacheService.cacheAlbums(CacheType.NEW) - } + val cacheType = if (withContext(ioDispatcher) { albumRepository.count() } == 0L) { + CacheType.ALL} + else { + CacheType.NEW + } + coroutineScope { + launch { + albumCacheService.cacheAlbums(cacheType) } } }