mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
chore(db): Clean up unused StorIO relics
This commit is contained in:
parent
7a20537cf9
commit
bfbc1f6742
13 changed files with 63 additions and 298 deletions
|
@ -71,6 +71,7 @@ import yokai.core.CrashlyticsLogWriter
|
|||
import yokai.core.RollingUniFileLogWriter
|
||||
import yokai.core.di.appModule
|
||||
import yokai.core.di.domainModule
|
||||
import yokai.core.di.initExpensiveComponents
|
||||
import yokai.core.di.preferenceModule
|
||||
import yokai.core.migration.Migrator
|
||||
import yokai.core.migration.migrations.migrations
|
||||
|
@ -106,6 +107,7 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
|||
startKoin {
|
||||
modules(preferenceModule(this@App), appModule(this@App), domainModule())
|
||||
}
|
||||
initExpensiveComponents(this)
|
||||
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database
|
||||
|
||||
import android.database.Cursor
|
||||
|
||||
fun Cursor.getBoolean(index: Int) = getLong(index) > 0
|
|
@ -1,45 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database
|
||||
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
||||
import co.touchlab.kermit.Logger
|
||||
import yokai.data.Database
|
||||
|
||||
class DbOpenCallback : AndroidSqliteDriver.Callback(Database.Schema) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Name of the database file.
|
||||
*/
|
||||
const val DATABASE_NAME = "tachiyomi.db"
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
Logger.d { "Creating new database..." }
|
||||
super.onCreate(db)
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
if (oldVersion < newVersion) {
|
||||
Logger.d { "Upgrading database from $oldVersion to $newVersion" }
|
||||
super.onUpgrade(db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigure(db: SupportSQLiteDatabase) {
|
||||
db.setForeignKeyConstraintsEnabled(true)
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database
|
||||
|
||||
import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite
|
||||
|
||||
interface DbProvider {
|
||||
|
||||
val db: DefaultStorIOSQLite
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.queries
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.DbProvider
|
||||
|
||||
interface TrackQueries : DbProvider {
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object CategoryTable {
|
||||
|
||||
const val TABLE = "categories"
|
||||
|
||||
const val COL_ID = "_id"
|
||||
|
||||
const val COL_NAME = "name"
|
||||
|
||||
const val COL_ORDER = "sort"
|
||||
|
||||
const val COL_FLAGS = "flags"
|
||||
|
||||
const val COL_MANGA_ORDER = "manga_order"
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object ChapterTable {
|
||||
|
||||
const val TABLE = "chapters"
|
||||
|
||||
const val COL_ID = "_id"
|
||||
|
||||
const val COL_MANGA_ID = "manga_id"
|
||||
|
||||
const val COL_URL = "url"
|
||||
|
||||
const val COL_NAME = "name"
|
||||
|
||||
const val COL_READ = "read"
|
||||
|
||||
const val COL_SCANLATOR = "scanlator"
|
||||
|
||||
const val COL_BOOKMARK = "bookmark"
|
||||
|
||||
const val COL_DATE_FETCH = "date_fetch"
|
||||
|
||||
const val COL_DATE_UPLOAD = "date_upload"
|
||||
|
||||
const val COL_LAST_PAGE_READ = "last_page_read"
|
||||
|
||||
const val COL_PAGES_LEFT = "pages_left"
|
||||
|
||||
const val COL_CHAPTER_NUMBER = "chapter_number"
|
||||
|
||||
const val COL_SOURCE_ORDER = "source_order"
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object HistoryTable {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
const val TABLE = "history"
|
||||
|
||||
/**
|
||||
* Id column name
|
||||
*/
|
||||
const val COL_ID = "history_id"
|
||||
|
||||
/**
|
||||
* Chapter id column name
|
||||
*/
|
||||
const val COL_CHAPTER_ID = "history_chapter_id"
|
||||
|
||||
/**
|
||||
* Last read column name
|
||||
*/
|
||||
const val COL_LAST_READ = "history_last_read"
|
||||
|
||||
/**
|
||||
* Time read column name
|
||||
*/
|
||||
const val COL_TIME_READ = "history_time_read"
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object MangaCategoryTable {
|
||||
|
||||
const val TABLE = "mangas_categories"
|
||||
|
||||
const val COL_ID = "_id"
|
||||
|
||||
const val COL_MANGA_ID = "manga_id"
|
||||
|
||||
const val COL_CATEGORY_ID = "category_id"
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object MangaTable {
|
||||
|
||||
const val TABLE = "mangas"
|
||||
|
||||
const val COL_ID = "_id"
|
||||
|
||||
const val COL_SOURCE = "source"
|
||||
|
||||
const val COL_URL = "url"
|
||||
|
||||
const val COL_ARTIST = "artist"
|
||||
|
||||
const val COL_AUTHOR = "author"
|
||||
|
||||
const val COL_DESCRIPTION = "description"
|
||||
|
||||
const val COL_GENRE = "genre"
|
||||
|
||||
const val COL_TITLE = "title"
|
||||
|
||||
const val COL_STATUS = "status"
|
||||
|
||||
const val COL_THUMBNAIL_URL = "thumbnail_url"
|
||||
|
||||
const val COL_FAVORITE = "favorite"
|
||||
|
||||
const val COL_LAST_UPDATE = "last_update"
|
||||
|
||||
const val COL_INITIALIZED = "initialized"
|
||||
|
||||
const val COL_VIEWER = "viewer"
|
||||
|
||||
const val COL_CHAPTER_FLAGS = "chapter_flags"
|
||||
|
||||
const val COL_HIDE_TITLE = "hide_title"
|
||||
|
||||
const val COL_DATE_ADDED = "date_added"
|
||||
|
||||
const val COL_FILTERED_SCANLATORS = "filtered_scanlators"
|
||||
|
||||
const val COL_UPDATE_STRATEGY = "update_strategy"
|
||||
|
||||
const val COL_COVER_LAST_MODIFIED = "cover_last_modified"
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object SearchMetadataTable {
|
||||
const val TABLE = "search_metadata"
|
||||
|
||||
const val COL_MANGA_ID = "manga_id"
|
||||
|
||||
const val COL_UPLOADER = "uploader"
|
||||
|
||||
const val COL_EXTRA = "extra"
|
||||
|
||||
const val COL_INDEXED_EXTRA = "indexed_extra"
|
||||
|
||||
const val COL_EXTRA_VERSION = "extra_version"
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.database.tables
|
||||
|
||||
object TrackTable {
|
||||
|
||||
const val TABLE = "manga_sync"
|
||||
|
||||
const val COL_ID = "_id"
|
||||
|
||||
const val COL_MANGA_ID = "manga_id"
|
||||
|
||||
const val COL_SYNC_ID = "sync_id"
|
||||
|
||||
const val COL_MEDIA_ID = "remote_id"
|
||||
|
||||
const val COL_LIBRARY_ID = "library_id"
|
||||
|
||||
const val COL_TITLE = "title"
|
||||
|
||||
const val COL_LAST_CHAPTER_READ = "last_chapter_read"
|
||||
|
||||
const val COL_STATUS = "status"
|
||||
|
||||
const val COL_SCORE = "score"
|
||||
|
||||
const val COL_TOTAL_CHAPTERS = "total_chapters"
|
||||
|
||||
const val COL_TRACKING_URL = "remote_url"
|
||||
|
||||
const val COL_START_DATE = "start_date"
|
||||
|
||||
const val COL_FINISH_DATE = "finish_date"
|
||||
|
||||
}
|
|
@ -1,16 +1,17 @@
|
|||
package yokai.core.di
|
||||
|
||||
import android.app.Application
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import app.cash.sqldelight.db.SqlDriver
|
||||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.chuckerteam.chucker.api.ChuckerCollector
|
||||
import com.chuckerteam.chucker.api.ChuckerInterceptor
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.core.storage.AndroidStorageFolderProvider
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.DbOpenCallback
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.library.CustomMangaManager
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
|
@ -25,9 +26,9 @@ import kotlinx.serialization.json.Json
|
|||
import nl.adaptivity.xmlutil.XmlDeclMode
|
||||
import nl.adaptivity.xmlutil.core.XmlVersion
|
||||
import nl.adaptivity.xmlutil.serialization.XML
|
||||
import org.koin.core.module.dsl.createdAtStart
|
||||
import org.koin.core.module.dsl.withOptions
|
||||
import org.koin.dsl.module
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.data.AndroidDatabaseHandler
|
||||
import yokai.data.Database
|
||||
import yokai.data.DatabaseHandler
|
||||
|
@ -37,50 +38,57 @@ import yokai.domain.storage.StorageManager
|
|||
fun appModule(app: Application) = module {
|
||||
single { app }
|
||||
|
||||
single<SupportSQLiteOpenHelper> {
|
||||
val configuration = SupportSQLiteOpenHelper.Configuration.builder(app)
|
||||
.callback(DbOpenCallback())
|
||||
.name(DbOpenCallback.DATABASE_NAME)
|
||||
.noBackupDirectory(false)
|
||||
.build()
|
||||
|
||||
/*
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// Support database inspector in Android Studio
|
||||
FrameworkSQLiteOpenHelperFactory().create(configuration)
|
||||
} else {
|
||||
RequerySQLiteOpenHelperFactory().create(configuration)
|
||||
}
|
||||
*/
|
||||
RequerySQLiteOpenHelperFactory().create(configuration)
|
||||
}
|
||||
|
||||
single<SqlDriver> {
|
||||
AndroidSqliteDriver(openHelper = get())
|
||||
/*
|
||||
AndroidSqliteDriver(
|
||||
schema = Database.Schema,
|
||||
context = app,
|
||||
name = "tachiyomi.db",
|
||||
factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// Support database inspector in Android Studio
|
||||
FrameworkSQLiteOpenHelperFactory()
|
||||
} else {
|
||||
RequerySQLiteOpenHelperFactory()
|
||||
// factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// // Support database inspector in Android Studio
|
||||
// FrameworkSQLiteOpenHelperFactory()
|
||||
// } else {
|
||||
// RequerySQLiteOpenHelperFactory()
|
||||
// },
|
||||
factory = 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()
|
||||
}
|
||||
|
||||
// Not sure if this is still needed, but just in case
|
||||
override fun onConfigure(db: SupportSQLiteDatabase) {
|
||||
db.setForeignKeyConstraintsEnabled(true)
|
||||
}
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
Logger.d { "Creating new database..." }
|
||||
super.onCreate(db)
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
if (oldVersion < newVersion) {
|
||||
Logger.d { "Upgrading database from $oldVersion to $newVersion" }
|
||||
super.onUpgrade(db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
},
|
||||
callback = get<DbOpenCallback>(),
|
||||
)
|
||||
*/
|
||||
}
|
||||
|
||||
single {
|
||||
Database(
|
||||
driver = get(),
|
||||
)
|
||||
} withOptions {
|
||||
createdAtStart()
|
||||
}
|
||||
|
||||
single<DatabaseHandler> { AndroidDatabaseHandler(get(), get()) }
|
||||
|
||||
single { ChapterCache(app) }
|
||||
|
@ -103,24 +111,16 @@ fun appModule(app: Application) = module {
|
|||
)
|
||||
}
|
||||
}
|
||||
} withOptions {
|
||||
createdAtStart()
|
||||
}
|
||||
|
||||
single { JavaScriptEngine(app) }
|
||||
|
||||
single { SourceManager(app, get()) } withOptions {
|
||||
createdAtStart()
|
||||
}
|
||||
single { SourceManager(app, get()) }
|
||||
single { ExtensionManager(app) }
|
||||
|
||||
single { DownloadManager(app) } withOptions {
|
||||
createdAtStart()
|
||||
}
|
||||
single { DownloadManager(app) }
|
||||
|
||||
single { CustomMangaManager(app) } withOptions {
|
||||
createdAtStart()
|
||||
}
|
||||
single { CustomMangaManager(app) }
|
||||
|
||||
single { TrackManager(app) }
|
||||
|
||||
|
@ -151,3 +151,19 @@ fun appModule(app: Application) = module {
|
|||
|
||||
single { SplashState() }
|
||||
}
|
||||
|
||||
// REF: https://github.com/jobobby04/TachiyomiSY/blob/26cfb4811fef4059fb7e8e03361c141932fec6b5/app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt#L177C1-L192C2
|
||||
fun initExpensiveComponents(app: Application) {
|
||||
// Asynchronously init expensive components for a faster cold start
|
||||
ContextCompat.getMainExecutor(app).execute {
|
||||
Injekt.get<NetworkHelper>()
|
||||
|
||||
Injekt.get<SourceManager>()
|
||||
|
||||
Injekt.get<Database>()
|
||||
|
||||
Injekt.get<DownloadManager>()
|
||||
|
||||
Injekt.get<CustomMangaManager>()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue