From 9e3b454b1b79a7725b3d3be4c85c1655ad80e18d Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 3 Jul 2022 01:05:38 +0200 Subject: [PATCH] Use SQLDelight for all MangaCategory related queries (#7441) --- .../tachiyomi/data/database/DatabaseHelper.kt | 3 +- .../database/queries/MangaCategoryQueries.kt | 31 ------------------- .../source/browse/BrowseSourcePresenter.kt | 12 ++++--- 3 files changed, 9 insertions(+), 37 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt index d0fb524a97..19535f6d2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt @@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.data.database.mappers.MangaTypeMapping import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory -import eu.kanade.tachiyomi.data.database.queries.MangaCategoryQueries import eu.kanade.tachiyomi.data.database.queries.MangaQueries /** @@ -17,7 +16,7 @@ import eu.kanade.tachiyomi.data.database.queries.MangaQueries class DatabaseHelper( openHelper: SupportSQLiteOpenHelper, ) : - MangaQueries, MangaCategoryQueries { + MangaQueries { override val db = DefaultStorIOSQLite.builder() .sqliteOpenHelper(openHelper) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt deleted file mode 100644 index 9f36dc578d..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt +++ /dev/null @@ -1,31 +0,0 @@ -package eu.kanade.tachiyomi.data.database.queries - -import com.pushtorefresh.storio.Queries -import com.pushtorefresh.storio.sqlite.queries.DeleteQuery -import eu.kanade.tachiyomi.data.database.DbProvider -import eu.kanade.tachiyomi.data.database.inTransaction -import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.models.MangaCategory -import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable - -interface MangaCategoryQueries : DbProvider { - - fun insertMangasCategories(mangasCategories: List) = db.put().objects(mangasCategories).prepare() - - fun deleteOldMangasCategories(mangas: List) = db.delete() - .byQuery( - DeleteQuery.builder() - .table(MangaCategoryTable.TABLE) - .where("${MangaCategoryTable.COL_MANGA_ID} IN (${Queries.placeholders(mangas.size)})") - .whereArgs(*mangas.map { it.id }.toTypedArray()) - .build(), - ) - .prepare() - - fun setMangaCategories(mangasCategories: List, mangas: List) { - db.inTransaction { - deleteOldMangasCategories(mangas).executeAsBlocking() - insertMangasCategories(mangasCategories).executeAsBlocking() - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index 7a144281b0..2b9152ea15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.browse.source.browse import android.os.Bundle import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.domain.category.interactor.GetCategories -import eu.kanade.domain.category.model.toDbCategory +import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga @@ -13,7 +13,6 @@ import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -74,6 +73,7 @@ open class BrowseSourcePresenter( private val getDuplicateLibraryManga: GetDuplicateLibraryManga = Injekt.get(), private val getCategories: GetCategories = Injekt.get(), private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(), + private val setMangaCategories: SetMangaCategories = Injekt.get(), private val insertTrack: InsertTrack = Injekt.get(), private val syncChaptersWithTrackServiceTwoWay: SyncChaptersWithTrackServiceTwoWay = Injekt.get(), ) : BasePresenter() { @@ -388,8 +388,12 @@ open class BrowseSourcePresenter( * @param manga the manga to move. */ private fun moveMangaToCategories(manga: Manga, categories: List) { - val mc = categories.filter { it.id != 0L }.map { MangaCategory.create(manga, it.toDbCategory()) } - db.setMangaCategories(mc, listOf(manga)) + presenterScope.launchIO { + setMangaCategories.await( + mangaId = manga.id!!, + categoryIds = categories.filter { it.id != 0L }.map { it.id }, + ) + } } /**