mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(backup): Retrieve manga with SQLDelight
This commit is contained in:
parent
ad070fd59a
commit
9b45767667
5 changed files with 19 additions and 10 deletions
|
@ -10,8 +10,8 @@ import eu.kanade.tachiyomi.data.backup.create.creators.MangaBackupCreator
|
||||||
import eu.kanade.tachiyomi.data.backup.create.creators.PreferenceBackupCreator
|
import eu.kanade.tachiyomi.data.backup.create.creators.PreferenceBackupCreator
|
||||||
import eu.kanade.tachiyomi.data.backup.create.creators.SourcesBackupCreator
|
import eu.kanade.tachiyomi.data.backup.create.creators.SourcesBackupCreator
|
||||||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import java.io.FileOutputStream
|
||||||
import eu.kanade.tachiyomi.util.system.e
|
import java.time.Instant
|
||||||
import kotlinx.serialization.protobuf.ProtoBuf
|
import kotlinx.serialization.protobuf.ProtoBuf
|
||||||
import okio.buffer
|
import okio.buffer
|
||||||
import okio.gzip
|
import okio.gzip
|
||||||
|
@ -19,10 +19,9 @@ import okio.sink
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import yokai.domain.backup.BackupPreferences
|
import yokai.domain.backup.BackupPreferences
|
||||||
|
import yokai.domain.manga.interactor.GetManga
|
||||||
import yokai.i18n.MR
|
import yokai.i18n.MR
|
||||||
import yokai.util.lang.getString
|
import yokai.util.lang.getString
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.time.Instant
|
|
||||||
|
|
||||||
class BackupCreator(
|
class BackupCreator(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
|
@ -30,21 +29,19 @@ class BackupCreator(
|
||||||
private val mangaBackupCreator: MangaBackupCreator = MangaBackupCreator(),
|
private val mangaBackupCreator: MangaBackupCreator = MangaBackupCreator(),
|
||||||
private val preferenceBackupCreator: PreferenceBackupCreator = PreferenceBackupCreator(),
|
private val preferenceBackupCreator: PreferenceBackupCreator = PreferenceBackupCreator(),
|
||||||
private val sourcesBackupCreator: SourcesBackupCreator = SourcesBackupCreator(),
|
private val sourcesBackupCreator: SourcesBackupCreator = SourcesBackupCreator(),
|
||||||
|
private val getManga: GetManga = Injekt.get(),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val parser = ProtoBuf
|
val parser = ProtoBuf
|
||||||
private val db: DatabaseHelper = Injekt.get()
|
|
||||||
private val backupPreferences: BackupPreferences = Injekt.get()
|
private val backupPreferences: BackupPreferences = Injekt.get()
|
||||||
|
|
||||||
@Suppress("RedundantSuspendModifier")
|
private suspend fun getDatabaseManga(includeReadManga: Boolean) =
|
||||||
private suspend fun getDatabaseManga(includeReadManga: Boolean) = db.inTransactionReturn {
|
getManga.awaitFavorites() +
|
||||||
db.getFavoriteMangas().executeAsBlocking() +
|
|
||||||
if (includeReadManga) {
|
if (includeReadManga) {
|
||||||
db.getReadNotInLibraryMangas().executeAsBlocking()
|
getManga.awaitReadNotFavorites()
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create backup Json file from database
|
* Create backup Json file from database
|
||||||
|
|
|
@ -23,6 +23,9 @@ class MangaRepositoryImpl(private val handler: DatabaseHandler) : MangaRepositor
|
||||||
override suspend fun getFavorites(): List<Manga> =
|
override suspend fun getFavorites(): List<Manga> =
|
||||||
handler.awaitList { mangasQueries.findFavorites(Manga::mapper) }
|
handler.awaitList { mangasQueries.findFavorites(Manga::mapper) }
|
||||||
|
|
||||||
|
override suspend fun getReadNotFavorites(): List<Manga> =
|
||||||
|
handler.awaitList { mangasQueries.findReadNotFavorites(Manga::mapper) }
|
||||||
|
|
||||||
override fun getMangaListAsFlow(): Flow<List<Manga>> =
|
override fun getMangaListAsFlow(): Flow<List<Manga>> =
|
||||||
handler.subscribeToList { mangasQueries.findAll(Manga::mapper) }
|
handler.subscribeToList { mangasQueries.findAll(Manga::mapper) }
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ interface MangaRepository {
|
||||||
suspend fun getMangaByUrlAndSource(url: String, source: Long): Manga?
|
suspend fun getMangaByUrlAndSource(url: String, source: Long): Manga?
|
||||||
suspend fun getMangaById(id: Long): Manga?
|
suspend fun getMangaById(id: Long): Manga?
|
||||||
suspend fun getFavorites(): List<Manga>
|
suspend fun getFavorites(): List<Manga>
|
||||||
|
suspend fun getReadNotFavorites(): List<Manga>
|
||||||
fun getMangaListAsFlow(): Flow<List<Manga>>
|
fun getMangaListAsFlow(): Flow<List<Manga>>
|
||||||
suspend fun getLibraryManga(): List<LibraryManga>
|
suspend fun getLibraryManga(): List<LibraryManga>
|
||||||
fun getLibraryMangaAsFlow(): Flow<List<LibraryManga>>
|
fun getLibraryMangaAsFlow(): Flow<List<LibraryManga>>
|
||||||
|
|
|
@ -11,4 +11,5 @@ class GetManga (
|
||||||
suspend fun awaitByUrlAndSource(url: String, source: Long) = mangaRepository.getMangaByUrlAndSource(url, source)
|
suspend fun awaitByUrlAndSource(url: String, source: Long) = mangaRepository.getMangaByUrlAndSource(url, source)
|
||||||
suspend fun awaitById(id: Long) = mangaRepository.getMangaById(id)
|
suspend fun awaitById(id: Long) = mangaRepository.getMangaById(id)
|
||||||
suspend fun awaitFavorites() = mangaRepository.getFavorites()
|
suspend fun awaitFavorites() = mangaRepository.getFavorites()
|
||||||
|
suspend fun awaitReadNotFavorites() = mangaRepository.getReadNotFavorites()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,13 @@ SELECT *
|
||||||
FROM mangas
|
FROM mangas
|
||||||
WHERE favorite = 1;
|
WHERE favorite = 1;
|
||||||
|
|
||||||
|
findReadNotFavorites:
|
||||||
|
SELECT *
|
||||||
|
FROM mangas
|
||||||
|
WHERE favorite = 0 AND _id IN (
|
||||||
|
SELECT chapters.manga_id FROM chapters WHERE read = 1 OR last_page_read != 0
|
||||||
|
);
|
||||||
|
|
||||||
insert:
|
insert:
|
||||||
INSERT INTO mangas (source, url, artist, author, description, genre, title, status, thumbnail_url, favorite, last_update, initialized, viewer, hide_title, chapter_flags, date_added, filtered_scanlators, update_strategy, cover_last_modified)
|
INSERT INTO mangas (source, url, artist, author, description, genre, title, status, thumbnail_url, favorite, last_update, initialized, viewer, hide_title, chapter_flags, date_added, filtered_scanlators, update_strategy, cover_last_modified)
|
||||||
VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :initialized, :viewer, :hideTitle, :chapterFlags, :dateAdded, :filteredScanlators, :updateStrategy, :coverLastModified);
|
VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :initialized, :viewer, :hideTitle, :chapterFlags, :dateAdded, :filteredScanlators, :updateStrategy, :coverLastModified);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue