From 069bd90c0f76d21bc6d99a51644926876415c113 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 3 Jul 2022 21:48:13 +0200 Subject: [PATCH] Cleanup data layer (#7450) --- .../data/chapter/ChapterRepositoryImpl.kt | 43 +++++++----------- .../kanade/data/manga/MangaRepositoryImpl.kt | 14 +++--- .../kanade/data/track/TrackRepositoryImpl.kt | 23 +++------- .../data/backup/AbstractBackupManager.kt | 14 +++--- app/src/main/sqldelight/data/mangas.sq | 44 ++----------------- 5 files changed, 39 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt index 8f1b37dec3..b5050670a5 100644 --- a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt @@ -41,39 +41,28 @@ class ChapterRepositoryImpl( } override suspend fun update(chapterUpdate: ChapterUpdate) { - handler.await { - chaptersQueries.update( - chapterUpdate.mangaId, - chapterUpdate.url, - chapterUpdate.name, - chapterUpdate.scanlator, - chapterUpdate.read?.toLong(), - chapterUpdate.bookmark?.toLong(), - chapterUpdate.lastPageRead, - chapterUpdate.chapterNumber?.toDouble(), - chapterUpdate.sourceOrder, - chapterUpdate.dateFetch, - chapterUpdate.dateUpload, - chapterId = chapterUpdate.id, - ) - } + partialUpdate(chapterUpdate) } override suspend fun updateAll(chapterUpdates: List) { + partialUpdate(*chapterUpdates.toTypedArray()) + } + + private suspend fun partialUpdate(vararg chapterUpdates: ChapterUpdate) { handler.await(inTransaction = true) { chapterUpdates.forEach { chapterUpdate -> chaptersQueries.update( - chapterUpdate.mangaId, - chapterUpdate.url, - chapterUpdate.name, - chapterUpdate.scanlator, - chapterUpdate.read?.toLong(), - chapterUpdate.bookmark?.toLong(), - chapterUpdate.lastPageRead, - chapterUpdate.chapterNumber?.toDouble(), - chapterUpdate.sourceOrder, - chapterUpdate.dateFetch, - chapterUpdate.dateUpload, + mangaId = chapterUpdate.mangaId, + url = chapterUpdate.url, + name = chapterUpdate.name, + scanlator = chapterUpdate.scanlator, + read = chapterUpdate.read?.toLong(), + bookmark = chapterUpdate.bookmark?.toLong(), + lastPageRead = chapterUpdate.lastPageRead, + chapterNumber = chapterUpdate.chapterNumber?.toDouble(), + sourceOrder = chapterUpdate.sourceOrder, + dateFetch = chapterUpdate.dateFetch, + dateUpload = chapterUpdate.dateUpload, chapterId = chapterUpdate.id, ) } diff --git a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt index 27aeb793ea..e5af0946aa 100644 --- a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt @@ -79,15 +79,15 @@ class MangaRepositoryImpl( genre = manga.genre, title = manga.title, status = manga.status, - thumbnail_url = manga.thumbnailUrl, + thumbnailUrl = manga.thumbnailUrl, favorite = manga.favorite, - last_update = manga.lastUpdate, - next_update = null, + lastUpdate = manga.lastUpdate, + nextUpdate = null, initialized = manga.initialized, - viewer = manga.viewerFlags, - chapter_flags = manga.chapterFlags, - cover_last_modified = manga.coverLastModified, - date_added = manga.dateAdded, + viewerFlags = manga.viewerFlags, + chapterFlags = manga.chapterFlags, + coverLastModified = manga.coverLastModified, + dateAdded = manga.dateAdded, ) mangasQueries.selectLastInsertedRowId() } diff --git a/app/src/main/java/eu/kanade/data/track/TrackRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/track/TrackRepositoryImpl.kt index 30481edaf4..f060b65522 100644 --- a/app/src/main/java/eu/kanade/data/track/TrackRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/track/TrackRepositoryImpl.kt @@ -37,27 +37,16 @@ class TrackRepositoryImpl( } override suspend fun insert(track: Track) { - handler.await { - manga_syncQueries.insert( - mangaId = track.mangaId, - syncId = track.syncId, - remoteId = track.remoteId, - libraryId = track.libraryId, - title = track.title, - lastChapterRead = track.lastChapterRead, - totalChapters = track.totalChapters, - status = track.status, - score = track.score, - remoteUrl = track.remoteUrl, - startDate = track.startDate, - finishDate = track.finishDate, - ) - } + insertValues(track) } override suspend fun insertAll(tracks: List) { + insertValues(*tracks.toTypedArray()) + } + + private suspend fun insertValues(vararg values: Track) { handler.await(inTransaction = true) { - tracks.forEach { mangaTrack -> + values.forEach { mangaTrack -> manga_syncQueries.insert( mangaId = mangaTrack.mangaId, syncId = mangaTrack.syncId, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt index 67daebb1d2..84c91951e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt @@ -86,15 +86,15 @@ abstract class AbstractBackupManager(protected val context: Context) { genre = manga.getGenres(), title = manga.title, status = manga.status.toLong(), - thumbnail_url = manga.thumbnail_url, + thumbnailUrl = manga.thumbnail_url, favorite = manga.favorite, - last_update = manga.last_update, - next_update = 0L, + lastUpdate = manga.last_update, + nextUpdate = 0L, initialized = manga.initialized, - viewer = manga.viewer_flags.toLong(), - chapter_flags = manga.chapter_flags.toLong(), - cover_last_modified = manga.cover_last_modified, - date_added = manga.date_added, + viewerFlags = manga.viewer_flags.toLong(), + chapterFlags = manga.chapter_flags.toLong(), + coverLastModified = manga.cover_last_modified, + dateAdded = manga.date_added, ) mangasQueries.selectLastInsertedRowId() } diff --git a/app/src/main/sqldelight/data/mangas.sq b/app/src/main/sqldelight/data/mangas.sq index 96b8f87d57..797b1e6b12 100644 --- a/app/src/main/sqldelight/data/mangas.sq +++ b/app/src/main/sqldelight/data/mangas.sq @@ -25,10 +25,6 @@ CREATE TABLE mangas( CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1; CREATE INDEX mangas_url_index ON mangas(url); -insert: -INSERT INTO mangas(source,url,artist,author,description,genre,title,status,thumbnail_url,favorite,last_update,next_update,initialized,viewer,chapter_flags,cover_last_modified,date_added) -VALUES (:source,:url,:artist,:author,:description,:genre,:title,:status,:thumbnail_url,:favorite,:last_update,:next_update,:initialized,:viewer,:chapter_flags,:cover_last_modified,:date_added); - getMangaById: SELECT * FROM mangas @@ -145,43 +141,9 @@ deleteMangasNotInLibraryBySourceIds: DELETE FROM mangas WHERE favorite = 0 AND source IN :sourceIds; -INSERT INTO mangas( - source, - url, - artist, - author, - description, - genre, - title, - status, - thumbnail_url, - favorite, - last_update, - next_update, - initialized, - viewer, - chapter_flags, - cover_last_modified, - date_added -) VALUES ( - :source, - :url, - :artist, - :author, - :description, - :genre, - :title, - :status, - :thumbnailUrl, - :favorite, - :lastUpdate, - 0, - :initialized, - :viewerFlags, - :chapterFlags, - :coverLastModified, - :dateAdded -); +insert: +INSERT INTO mangas(source,url,artist,author,description,genre,title,status,thumbnail_url,favorite,last_update,next_update,initialized,viewer,chapter_flags,cover_last_modified,date_added) +VALUES (:source,:url,:artist,:author,:description,:genre,:title,:status,:thumbnailUrl,:favorite,:lastUpdate,:nextUpdate,:initialized,:viewerFlags,:chapterFlags,:coverLastModified,:dateAdded); update: UPDATE mangas SET