mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 03:18:25 +01:00
Cleanup data layer (#7450)
This commit is contained in:
parent
68697e59d7
commit
069bd90c0f
@ -41,39 +41,28 @@ class ChapterRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(chapterUpdate: ChapterUpdate) {
|
override suspend fun update(chapterUpdate: ChapterUpdate) {
|
||||||
handler.await {
|
partialUpdate(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,
|
|
||||||
chapterId = chapterUpdate.id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateAll(chapterUpdates: List<ChapterUpdate>) {
|
override suspend fun updateAll(chapterUpdates: List<ChapterUpdate>) {
|
||||||
|
partialUpdate(*chapterUpdates.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun partialUpdate(vararg chapterUpdates: ChapterUpdate) {
|
||||||
handler.await(inTransaction = true) {
|
handler.await(inTransaction = true) {
|
||||||
chapterUpdates.forEach { chapterUpdate ->
|
chapterUpdates.forEach { chapterUpdate ->
|
||||||
chaptersQueries.update(
|
chaptersQueries.update(
|
||||||
chapterUpdate.mangaId,
|
mangaId = chapterUpdate.mangaId,
|
||||||
chapterUpdate.url,
|
url = chapterUpdate.url,
|
||||||
chapterUpdate.name,
|
name = chapterUpdate.name,
|
||||||
chapterUpdate.scanlator,
|
scanlator = chapterUpdate.scanlator,
|
||||||
chapterUpdate.read?.toLong(),
|
read = chapterUpdate.read?.toLong(),
|
||||||
chapterUpdate.bookmark?.toLong(),
|
bookmark = chapterUpdate.bookmark?.toLong(),
|
||||||
chapterUpdate.lastPageRead,
|
lastPageRead = chapterUpdate.lastPageRead,
|
||||||
chapterUpdate.chapterNumber?.toDouble(),
|
chapterNumber = chapterUpdate.chapterNumber?.toDouble(),
|
||||||
chapterUpdate.sourceOrder,
|
sourceOrder = chapterUpdate.sourceOrder,
|
||||||
chapterUpdate.dateFetch,
|
dateFetch = chapterUpdate.dateFetch,
|
||||||
chapterUpdate.dateUpload,
|
dateUpload = chapterUpdate.dateUpload,
|
||||||
chapterId = chapterUpdate.id,
|
chapterId = chapterUpdate.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -79,15 +79,15 @@ class MangaRepositoryImpl(
|
|||||||
genre = manga.genre,
|
genre = manga.genre,
|
||||||
title = manga.title,
|
title = manga.title,
|
||||||
status = manga.status,
|
status = manga.status,
|
||||||
thumbnail_url = manga.thumbnailUrl,
|
thumbnailUrl = manga.thumbnailUrl,
|
||||||
favorite = manga.favorite,
|
favorite = manga.favorite,
|
||||||
last_update = manga.lastUpdate,
|
lastUpdate = manga.lastUpdate,
|
||||||
next_update = null,
|
nextUpdate = null,
|
||||||
initialized = manga.initialized,
|
initialized = manga.initialized,
|
||||||
viewer = manga.viewerFlags,
|
viewerFlags = manga.viewerFlags,
|
||||||
chapter_flags = manga.chapterFlags,
|
chapterFlags = manga.chapterFlags,
|
||||||
cover_last_modified = manga.coverLastModified,
|
coverLastModified = manga.coverLastModified,
|
||||||
date_added = manga.dateAdded,
|
dateAdded = manga.dateAdded,
|
||||||
)
|
)
|
||||||
mangasQueries.selectLastInsertedRowId()
|
mangasQueries.selectLastInsertedRowId()
|
||||||
}
|
}
|
||||||
|
@ -37,27 +37,16 @@ class TrackRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun insert(track: Track) {
|
override suspend fun insert(track: Track) {
|
||||||
handler.await {
|
insertValues(track)
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun insertAll(tracks: List<Track>) {
|
override suspend fun insertAll(tracks: List<Track>) {
|
||||||
|
insertValues(*tracks.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun insertValues(vararg values: Track) {
|
||||||
handler.await(inTransaction = true) {
|
handler.await(inTransaction = true) {
|
||||||
tracks.forEach { mangaTrack ->
|
values.forEach { mangaTrack ->
|
||||||
manga_syncQueries.insert(
|
manga_syncQueries.insert(
|
||||||
mangaId = mangaTrack.mangaId,
|
mangaId = mangaTrack.mangaId,
|
||||||
syncId = mangaTrack.syncId,
|
syncId = mangaTrack.syncId,
|
||||||
|
@ -86,15 +86,15 @@ abstract class AbstractBackupManager(protected val context: Context) {
|
|||||||
genre = manga.getGenres(),
|
genre = manga.getGenres(),
|
||||||
title = manga.title,
|
title = manga.title,
|
||||||
status = manga.status.toLong(),
|
status = manga.status.toLong(),
|
||||||
thumbnail_url = manga.thumbnail_url,
|
thumbnailUrl = manga.thumbnail_url,
|
||||||
favorite = manga.favorite,
|
favorite = manga.favorite,
|
||||||
last_update = manga.last_update,
|
lastUpdate = manga.last_update,
|
||||||
next_update = 0L,
|
nextUpdate = 0L,
|
||||||
initialized = manga.initialized,
|
initialized = manga.initialized,
|
||||||
viewer = manga.viewer_flags.toLong(),
|
viewerFlags = manga.viewer_flags.toLong(),
|
||||||
chapter_flags = manga.chapter_flags.toLong(),
|
chapterFlags = manga.chapter_flags.toLong(),
|
||||||
cover_last_modified = manga.cover_last_modified,
|
coverLastModified = manga.cover_last_modified,
|
||||||
date_added = manga.date_added,
|
dateAdded = manga.date_added,
|
||||||
)
|
)
|
||||||
mangasQueries.selectLastInsertedRowId()
|
mangasQueries.selectLastInsertedRowId()
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@ CREATE TABLE mangas(
|
|||||||
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
|
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
|
||||||
CREATE INDEX mangas_url_index ON mangas(url);
|
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:
|
getMangaById:
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM mangas
|
FROM mangas
|
||||||
@ -145,43 +141,9 @@ deleteMangasNotInLibraryBySourceIds:
|
|||||||
DELETE FROM mangas
|
DELETE FROM mangas
|
||||||
WHERE favorite = 0 AND source IN :sourceIds;
|
WHERE favorite = 0 AND source IN :sourceIds;
|
||||||
|
|
||||||
INSERT INTO mangas(
|
insert:
|
||||||
source,
|
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)
|
||||||
url,
|
VALUES (:source,:url,:artist,:author,:description,:genre,:title,:status,:thumbnailUrl,:favorite,:lastUpdate,:nextUpdate,:initialized,:viewerFlags,:chapterFlags,:coverLastModified,:dateAdded);
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
update:
|
update:
|
||||||
UPDATE mangas SET
|
UPDATE mangas SET
|
||||||
|
Loading…
Reference in New Issue
Block a user