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:
AntsyLich
2026-09-27 22:36:13 +06:00
parent 306befb214
commit f8fff318ba
21 changed files with 155 additions and 172 deletions
@@ -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)