Split the universal update queries into case-specific ones

Source-owned fields move out of MangaUpdate/ChapterUpdate into MangaRemoteUpdate/ChapterRemoteUpdate, which only UpdateMangaFromRemote and SyncChaptersWithSource write. Backup restore gets its own updateFromBackup queries for entries and chapters, writing only what a backup carries.
This commit is contained in:
AntsyLich
2026-09-27 21:50:38 +06:00
parent c67a33f3d4
commit a4abb6292b
14 changed files with 158 additions and 111 deletions
@@ -80,15 +80,26 @@ RETURNING _id;
update:
UPDATE chapters
SET manga_id = coalesce(:mangaId, manga_id),
url = coalesce(:url, url),
name = coalesce(:name, name),
scanlator = coalesce(:scanlator, scanlator),
read = coalesce(:read, read),
bookmark = coalesce(:bookmark, bookmark),
last_page_read = coalesce(:lastPageRead, last_page_read),
chapter_number = coalesce(:chapterNumber, chapter_number),
source_order = coalesce(:sourceOrder, source_order),
date_fetch = coalesce(:dateFetch, date_fetch),
date_upload = coalesce(:dateUpload, date_upload),
date_fetch = coalesce(:dateFetch, date_fetch)
WHERE _id = :chapterId;
updateFromBackup:
UPDATE chapters
SET read = coalesce(:read, read),
bookmark = coalesce(:bookmark, bookmark),
last_page_read = coalesce(:lastPageRead, last_page_read),
memo = coalesce(:memo, memo)
WHERE _id = :chapterId;
updateRemote:
UPDATE chapters
SET name = :name,
scanlator = coalesce(:scanlator, scanlator),
chapter_number = :chapterNumber,
source_order = :sourceOrder,
date_upload = coalesce(:dateUpload, date_upload),
memo = :memo
WHERE _id = :chapterId;
@@ -203,8 +203,19 @@ RETURNING _id;
update:
UPDATE mangas SET
source = coalesce(:source, source),
url = coalesce(:url, url),
favorite = coalesce(:favorite, favorite),
last_update = coalesce(:lastUpdate, last_update),
next_update = coalesce(:nextUpdate, next_update),
viewer = coalesce(:viewer, viewer),
chapter_flags = coalesce(:chapterFlags, chapter_flags),
cover_last_modified = coalesce(:coverLastModified, cover_last_modified),
date_added = coalesce(:dateAdded, date_added),
calculate_interval = coalesce(:calculateInterval, calculate_interval),
notes = coalesce(:notes, notes)
WHERE _id = :mangaId;
updateFromBackup:
UPDATE mangas SET
artist = coalesce(:artist, artist),
author = coalesce(:author, author),
description = coalesce(:description, description),
@@ -214,18 +225,31 @@ UPDATE mangas SET
thumbnail_url = coalesce(:thumbnailUrl, thumbnail_url),
favorite = coalesce(:favorite, favorite),
last_update = coalesce(:lastUpdate, last_update),
next_update = coalesce(:nextUpdate, next_update),
initialized = coalesce(:initialized, initialized),
viewer = coalesce(:viewer, viewer),
chapter_flags = coalesce(:chapterFlags, chapter_flags),
cover_last_modified = coalesce(:coverLastModified, cover_last_modified),
date_added = coalesce(:dateAdded, date_added),
update_strategy = coalesce(:updateStrategy, update_strategy),
calculate_interval = coalesce(:calculateInterval, calculate_interval),
notes = coalesce(:notes, notes),
memo = coalesce(:memo, memo)
WHERE _id = :mangaId;
updateRemote:
UPDATE mangas SET
artist = coalesce(:artist, artist),
author = coalesce(:author, author),
description = coalesce(:description, description),
genre = coalesce(:genre, genre),
title = coalesce(:title, title),
status = :status,
thumbnail_url = coalesce(:thumbnailUrl, thumbnail_url),
initialized = :initialized,
cover_last_modified = coalesce(:coverLastModified, cover_last_modified),
update_strategy = :updateStrategy,
memo = :memo
WHERE _id = :mangaId;
insertNetworkManga {
-- Insert the manga if it doesn't exist already
INSERT INTO mangas(