Convert clear database queries to SQLDelight

(cherry picked from commit e15a867106)

# Conflicts:
#	app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt
#	app/src/main/java/eu/kanade/domain/DomainModule.kt
#	app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
#	app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/database/ClearDatabasePresenter.kt
This commit is contained in:
arkon
2022-06-10 21:33:56 -04:00
committed by Jobobby04
parent 35d9f24d5f
commit c4def072f6
13 changed files with 83 additions and 131 deletions
@@ -8,12 +8,12 @@ import eu.kanade.tachiyomi.util.system.logcat
import logcat.LogPriority
class ChapterRepositoryImpl(
private val databaseHandler: DatabaseHandler,
private val handler: DatabaseHandler,
) : ChapterRepository {
override suspend fun update(chapterUpdate: ChapterUpdate) {
try {
databaseHandler.await {
handler.await {
chaptersQueries.update(
chapterUpdate.mangaId,
chapterUpdate.url,
@@ -8,16 +8,16 @@ import kotlinx.coroutines.flow.Flow
import logcat.LogPriority
class MangaRepositoryImpl(
private val databaseHandler: DatabaseHandler,
private val handler: DatabaseHandler,
) : MangaRepository {
override fun getFavoritesBySourceId(sourceId: Long): Flow<List<Manga>> {
return databaseHandler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) }
return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) }
}
override suspend fun resetViewerFlags(): Boolean {
return try {
databaseHandler.await { mangasQueries.resetViewerFlags() }
handler.await { mangasQueries.resetViewerFlags() }
true
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
@@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import exh.source.MERGED_SOURCE_ID
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import eu.kanade.tachiyomi.source.Source as LoadedSource
class SourceRepositoryImpl(
private val sourceManager: SourceManager,
@@ -30,13 +31,23 @@ class SourceRepositoryImpl(
val sourceIdWithFavoriteCount = handler.subscribeToList { mangasQueries.getSourceIdWithFavoriteCount() }
return sourceIdWithFavoriteCount.map { sourceIdsWithCount ->
sourceIdsWithCount
.filterNot { it.source == LocalSource.ID /* SY --> */ || it.source == MERGED_SOURCE_ID /* SY <-- */ }
.map { (sourceId, count) ->
val source = sourceManager.getOrStub(sourceId).run {
sourceMapper(this)
}
source to count
}
.filterNot { it.first.id == LocalSource.ID /* SY --> */ || it.first.id == MERGED_SOURCE_ID /* SY <-- */ }
}
}
override fun getSourcesWithNonLibraryManga(): Flow<List<Pair<LoadedSource, Long>>> {
val sourceIdWithNonLibraryManga = handler.subscribeToList { mangasQueries.getSourceIdsWithNonLibraryManga() }
return sourceIdWithNonLibraryManga.map { sourceId ->
sourceId.map { (sourceId, count) ->
val source = sourceManager.getOrStub(sourceId)
source to count
}
}
}
}