From d977b89af1f2a8850437ebd978535fc3fbfd257e Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 9 Jul 2022 23:35:49 +0200 Subject: [PATCH] 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 --- app/src/main/java/eu/kanade/tachiyomi/AppModule.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index bee6ebce2c..26032ce6ef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -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() + } + }, ) }