mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-16 13:48:09 -07:00
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.