mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-16 13:48:09 -07:00
Build manga and chapter updates with a lambda and track assigned fields
MangaUpdate and ChapterUpdate are built with a lambda that records which fields were assigned, so an update writes only those fields.
This commit is contained in:
@@ -82,7 +82,6 @@ class ChapterRepositoryImpl(
|
||||
database.transaction {
|
||||
chapterUpdates.forEach { chapterUpdate ->
|
||||
database.chaptersQueries.update(
|
||||
mangaId = chapterUpdate.mangaId,
|
||||
read = chapterUpdate.read,
|
||||
bookmark = chapterUpdate.bookmark,
|
||||
lastPageRead = chapterUpdate.lastPageRead,
|
||||
|
||||
@@ -245,18 +245,20 @@ class MangaRepositoryImpl(
|
||||
private suspend fun partialUpdate(vararg mangaUpdates: MangaUpdate) {
|
||||
database.transaction {
|
||||
mangaUpdates.forEach { value ->
|
||||
database.mangasQueries.update(
|
||||
favorite = value.favorite,
|
||||
lastUpdate = value.lastUpdate,
|
||||
nextUpdate = value.nextUpdate,
|
||||
calculateInterval = value.fetchInterval?.toLong(),
|
||||
viewer = value.viewerFlags,
|
||||
chapterFlags = value.chapterFlags,
|
||||
coverLastModified = value.coverLastModified,
|
||||
dateAdded = value.dateAdded,
|
||||
mangaId = value.id,
|
||||
notes = value.notes,
|
||||
)
|
||||
with(value) {
|
||||
database.mangasQueries.update(
|
||||
favorite = favorite,
|
||||
lastUpdate = lastUpdate,
|
||||
nextUpdate = nextUpdate,
|
||||
calculateInterval = fetchInterval?.toLong(),
|
||||
viewer = viewerFlags,
|
||||
chapterFlags = chapterFlags,
|
||||
coverLastModified = coverLastModified,
|
||||
dateAdded = dateAdded,
|
||||
mangaId = id,
|
||||
notes = notes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,7 @@ RETURNING _id;
|
||||
|
||||
update:
|
||||
UPDATE chapters
|
||||
SET manga_id = coalesce(:mangaId, manga_id),
|
||||
read = coalesce(:read, read),
|
||||
SET read = coalesce(:read, read),
|
||||
bookmark = coalesce(:bookmark, bookmark),
|
||||
last_page_read = coalesce(:lastPageRead, last_page_read),
|
||||
date_fetch = coalesce(:dateFetch, date_fetch)
|
||||
|
||||
Reference in New Issue
Block a user