Files
mihon-bookmod/data/src/main/sqldelight/tachiyomi/view/updatesView.sq
T
AntsyLich e21414b229 Drop the legacy chapter model and narrow last page read to an Int
eu.kanade.tachiyomi.data.database.models.Chapter predates SQLDelight. It
survived because it implements SChapter, so ReaderChapter could hand the
same object to the database and to the source.

ReaderChapter now holds the domain Chapter and converts at the three
points that actually need a source model: getPageList, getFormat and
getChapterUrl. The domain model is immutable, so the reader replaces the
chapter rather than writing through it, behind an update function so the
field cannot be reassigned from outside. Equality stays on the chapter it
was loaded with, which keeps the identity comparisons in the viewers
stable while progress is recorded against it.

updateChapterProgress no longer mutates the chapter and reads the values
straight back out to build the update it persists; it computes them once
and passes them. Marking a chapter read moves out of the function named
for completing it and into the same place the page is recorded.

Removing the interface also drops the nullable id it carried, along with
three non-null assertions and a Float to Double conversion that the
compiler had been warning about.

A page position is an index into a chapter's pages, so it cannot exceed
Int range, but SQLite has one integer type and the column came back as a
Long. That width reached the domain model and then every caller either
carried it or converted, and the viewers had to narrow it again to index
a list with.

Declaring the column INTEGER AS Int moves the narrowing into a column
adapter, so it happens once where the value stops being a database
number. No migration: SQLite still stores an INTEGER, only the type
SQLDelight generates changes.

Backups are the exception and keep converting, because the field is on
the wire as int64 and has to stay that way. That is also the only place
the value arrives from outside the app, where a malformed file could
carry something that does not fit and truncate to a negative index, so
it is clamped rather than cast.
2026-10-10 17:37:44 +06:00

97 lines
3.2 KiB
Plaintext

import kotlin.Int;
CREATE VIEW updatesView AS
SELECT
manga.id AS mangaId,
manga.remote_title AS mangaTitle,
chapter.id AS chapterId,
chapter.remote_name AS chapterName,
chapter.remote_scanlator AS scanlator,
chapter.remote_url AS chapterUrl,
chapter.user_read AS read,
chapter.user_bookmark AS bookmark,
chapter.user_last_page_read AS lastPageRead,
manga.source_id AS sourceId,
manga.user_favorite_at IS NOT NULL AS favorite,
manga.remote_cover AS thumbnailUrl,
manga.state_cover_last_modified AS coverLastModified,
chapter.remote_date_upload AS dateUpload,
chapter.state_date_fetch AS dateFetch,
excluded_scanlator.scanlator AS excludedScanlator
FROM manga JOIN chapter
ON manga.id = chapter.manga_id
LEFT JOIN excluded_scanlator
ON manga.id = excluded_scanlator.manga_id
AND chapter.remote_scanlator = excluded_scanlator.scanlator
WHERE user_favorite_at IS NOT NULL
AND state_date_fetch > user_favorite_at
ORDER BY state_date_fetch DESC;
getRecentUpdatesWithFilters:
SELECT
mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark,
lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch,
excludedScanlator
FROM updatesView
WHERE dateUpload > :after
AND (:read IS NULL OR read = :read)
-- Started means some progress but not finished, Read means finished chapter, thus:
AND (
:started IS NULL
OR (:started = 1 AND lastPageRead > 0 AND read = 0)
OR (:started = 0 AND lastPageRead = 0 AND read = 0)
)
AND (:bookmarked IS NULL OR bookmark = :bookmarked)
AND (excludedScanlator IS NULL OR :hideExcludedScanlators = 0)
AND (
-- includedEmpty being true expresses "don't care" state and bypasses the membership filter
:includedEmpty
OR EXISTS (
SELECT 1 FROM manga_category
WHERE manga_category.manga_id = mangaId
AND manga_category.category_id IN :includedCategories
)
OR (0 IN :includedCategories AND NOT EXISTS (
SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId)
)
)
AND (
-- excludedEmpty being true expresses "don't care" state and bypasses the membership filter
:excludedEmpty
OR (
NOT EXISTS (
SELECT 1 FROM manga_category
WHERE manga_category.manga_id = mangaId
AND manga_category.category_id IN :excludedCategories
)
AND (
0 NOT IN :excludedCategories
OR EXISTS (SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId)
)
)
)
ORDER BY dateFetch DESC
LIMIT :limit;
getReadUpdates:
SELECT
mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark,
lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch,
excludedScanlator
FROM updatesView
WHERE read = 1
AND dateUpload > :after
ORDER BY dateFetch DESC
LIMIT :limit;
getUnreadUpdates:
SELECT
mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark,
lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch,
excludedScanlator
FROM updatesView
WHERE read = 0
AND dateUpload > :after
ORDER BY dateFetch DESC
LIMIT :limit;