use a singleton single threaded executor for handling Room db queries

This commit is contained in:
tibbi 2018-10-25 17:43:41 +02:00
parent 1321ccae66
commit 1c2812db48
2 changed files with 10 additions and 1 deletions

View File

@ -1,9 +1,10 @@
package com.simplemobiletools.gallery.databases package com.simplemobiletools.gallery.databases
import android.content.Context
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import android.content.Context import com.simplemobiletools.gallery.objects.MyExecutor
import com.simplemobiletools.gallery.interfaces.DirectoryDao import com.simplemobiletools.gallery.interfaces.DirectoryDao
import com.simplemobiletools.gallery.interfaces.MediumDao import com.simplemobiletools.gallery.interfaces.MediumDao
import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Directory
@ -25,6 +26,7 @@ abstract class GalleryDatabase : RoomDatabase() {
if (db == null) { if (db == null) {
db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db") db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db")
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()
.setQueryExecutor(MyExecutor.myExecutor)
.build() .build()
db!!.openHelper.setWriteAheadLoggingEnabled(true) db!!.openHelper.setWriteAheadLoggingEnabled(true)
} }

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.gallery.objects
import java.util.concurrent.Executors
object MyExecutor {
val myExecutor = Executors.newSingleThreadExecutor()
}