Configure SQLite (#7495)
- Turn on `foreign_keys` to cascade on delete properly - Turn on `journal_mode` and set `synchronous` to NORMAL which may help performance for larger libraries
Cette révision appartient à :
Parent
487ce37d91
révision
d977b89af1
1 fichiers modifiés avec 14 ajouts et 0 suppressions
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi
|
|||
import android.app.Application
|
||||
import android.os.Build
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
||||
import com.squareup.sqldelight.android.AndroidSqliteDriver
|
||||
import com.squareup.sqldelight.db.SqlDriver
|
||||
|
@ -46,6 +47,19 @@ class AppModule(val app: Application) : InjektModule {
|
|||
} else {
|
||||
RequerySQLiteOpenHelperFactory()
|
||||
},
|
||||
callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
|
||||
override fun onOpen(db: SupportSQLiteDatabase) {
|
||||
super.onOpen(db)
|
||||
setPragma(db, "foreign_keys = ON")
|
||||
setPragma(db, "journal_mode = WAL")
|
||||
setPragma(db, "synchronous = NORMAL")
|
||||
}
|
||||
private fun setPragma(db: SupportSQLiteDatabase, pragma: String) {
|
||||
val cursor = db.query("PRAGMA $pragma")
|
||||
cursor.moveToFirst()
|
||||
cursor.close()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket