Skip to content

Commit

Permalink
feat: use coroutines IO Dispatcher for database queries, reducing the…
Browse files Browse the repository at this point in the history
… active total number of threads
  • Loading branch information
cbeyls committed Jan 3, 2025
1 parent abf7795 commit 215473e
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.runBlocking
import javax.inject.Named
import javax.inject.Singleton
Expand Down Expand Up @@ -94,6 +96,7 @@ object DatabaseModule {
val onDatabaseOpen = CompletableDeferred<Unit>()

return Room.databaseBuilder(context, AppDatabase::class.java, DB_FILE)
.setQueryExecutor(Dispatchers.IO.asExecutor())
.setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
.addMigrations(migration3to5, migration5to6, migration6to7)
.fallbackToDestructiveMigration()
Expand Down

0 comments on commit 215473e

Please sign in to comment.