use a singleton single threaded executor for handling Room db queries
This commit is contained in:
parent
1321ccae66
commit
1c2812db48
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.simplemobiletools.gallery.objects
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
object MyExecutor {
|
||||||
|
val myExecutor = Executors.newSingleThreadExecutor()
|
||||||
|
}
|
Loading…
Reference in New Issue