Skip to content

Commit

Permalink
Fix database updater worker crashes when there's more than a single m…
Browse files Browse the repository at this point in the history
…edia update

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Nov 16, 2024
1 parent b739704 commit fa9a6ba
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.withContext

fun WorkManager.updateDatabase() {
Expand Down Expand Up @@ -52,8 +52,8 @@ class DatabaseUpdaterWorker @AssistedInject constructor(
val mediaVersion = appContext.mediaStoreVersion
printDebug("Database is not up to date. Updating to version $mediaVersion")
database.getMediaDao().setMediaVersion(MediaVersion(mediaVersion))
val media = repository.getMedia().map { it.data ?: emptyList() }.single()
database.getMediaDao().updateMedia(media)
val media = repository.getMedia().map { it.data ?: emptyList() }.firstOrNull()
media?.let { database.getMediaDao().updateMedia(it) }
delay(5000)
}

Expand Down

0 comments on commit fa9a6ba

Please sign in to comment.