Adapt model implementation for TachiyomiX 1.6 (#3412)

This commit is contained in:
AntsyLich
2026-06-15 23:32:39 +06:00
committed by GitHub
parent f00cac265f
commit 94cab02c1e
26 changed files with 177 additions and 28 deletions
@@ -2,6 +2,10 @@ package tachiyomi.data
import app.cash.sqldelight.ColumnAdapter
import eu.kanade.tachiyomi.source.model.UpdateStrategy
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.encodeToJsonElement
import kotlinx.serialization.json.jsonObject
import java.util.Date
object DateColumnAdapter : ColumnAdapter<Date, Long> {
@@ -27,3 +31,13 @@ object UpdateStrategyColumnAdapter : ColumnAdapter<UpdateStrategy, Long> {
override fun encode(value: UpdateStrategy): Long = value.ordinal.toLong()
}
object MemoColumnAdapter : ColumnAdapter<JsonObject, ByteArray> {
override fun decode(databaseValue: ByteArray): JsonObject {
return Json.decodeFromString<JsonObject>(databaseValue.decodeToString())
}
override fun encode(value: JsonObject): ByteArray {
return value.toString().encodeToByteArray()
}
}
@@ -4,10 +4,13 @@ import app.cash.sqldelight.async.coroutines.awaitAsList
import app.cash.sqldelight.async.coroutines.awaitAsOne
import app.cash.sqldelight.async.coroutines.awaitAsOneOrNull
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.json.JsonObject
import logcat.LogPriority
import tachiyomi.core.common.util.lang.toLong
import tachiyomi.core.common.util.system.logcat
import tachiyomi.data.Database
import tachiyomi.data.MemoColumnAdapter
import tachiyomi.data.MemoColumnAdapter.encode
import tachiyomi.data.subscribeToList
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.chapter.model.ChapterUpdate
@@ -34,6 +37,7 @@ class ChapterRepositoryImpl(
chapter.dateFetch,
chapter.dateUpload,
chapter.version,
chapter.memo,
)
.awaitAsOne()
chapter.copy(id = chapterId)
@@ -71,6 +75,7 @@ class ChapterRepositoryImpl(
chapterId = chapterUpdate.id,
version = chapterUpdate.version,
isSyncing = 0,
memo = chapterUpdate.memo?.let(MemoColumnAdapter::encode),
)
}
}
@@ -143,6 +148,7 @@ class ChapterRepositoryImpl(
lastModifiedAt: Long,
version: Long,
isSyncing: Long,
memo: JsonObject,
): Chapter = Chapter(
id = id,
mangaId = mangaId,
@@ -158,5 +164,6 @@ class ChapterRepositoryImpl(
scanlator = scanlator,
lastModifiedAt = lastModifiedAt,
version = version,
memo = memo,
)
}
@@ -1,6 +1,7 @@
package tachiyomi.data.manga
import eu.kanade.tachiyomi.source.model.UpdateStrategy
import kotlinx.serialization.json.JsonObject
import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.MangaWithChapterCount
@@ -33,6 +34,7 @@ object MangaMapper {
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
): Manga = Manga(
id = id,
source = source,
@@ -58,6 +60,7 @@ object MangaMapper {
favoriteModifiedAt = favoriteModifiedAt,
version = version,
notes = notes,
memo = memo,
)
fun mapLibraryManga(
@@ -86,6 +89,7 @@ object MangaMapper {
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
totalCount: Long,
readCount: Double,
latestUpload: Long,
@@ -120,6 +124,7 @@ object MangaMapper {
version,
isSyncing,
notes,
memo,
),
categories = categories.split(",").map { it.toLong() },
totalChapters = totalCount,
@@ -156,6 +161,7 @@ object MangaMapper {
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
totalCount: Long,
): MangaWithChapterCount = MangaWithChapterCount(
manga = mapManga(
@@ -184,6 +190,7 @@ object MangaMapper {
version,
isSyncing,
notes,
memo,
),
chapterCount = totalCount,
)
@@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.Flow
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat
import tachiyomi.data.Database
import tachiyomi.data.MemoColumnAdapter
import tachiyomi.data.StringListColumnAdapter
import tachiyomi.data.UpdateStrategyColumnAdapter
import tachiyomi.data.subscribeToList
@@ -154,6 +155,7 @@ class MangaRepositoryImpl(
dateAdded = it.dateAdded,
updateStrategy = it.updateStrategy,
version = it.version,
memo = it.memo,
updateTitle = it.title.isNotBlank(),
updateCover = !it.thumbnailUrl.isNullOrBlank(),
updateDetails = it.initialized,
@@ -191,6 +193,7 @@ class MangaRepositoryImpl(
version = value.version,
isSyncing = 0,
notes = value.notes,
memo = value.memo?.let(MemoColumnAdapter::encode),
)
}
}
@@ -1,4 +1,5 @@
import kotlin.Boolean;
import kotlinx.serialization.json.JsonObject;
CREATE TABLE chapters(
_id INTEGER NOT NULL PRIMARY KEY,
@@ -16,6 +17,7 @@ CREATE TABLE chapters(
last_modified_at INTEGER NOT NULL DEFAULT 0,
version INTEGER NOT NULL DEFAULT 0,
is_syncing INTEGER NOT NULL DEFAULT 0,
memo BLOB AS JsonObject NOT NULL DEFAULT '{}',
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
ON DELETE CASCADE
);
@@ -98,12 +100,12 @@ SET is_syncing = 0
WHERE is_syncing = 1;
insert:
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, last_modified_at, version, is_syncing)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0);
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, last_modified_at, version, is_syncing, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0, :memo);
insertReturningId:
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, last_modified_at, version, is_syncing)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0)
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, last_modified_at, version, is_syncing, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0, :memo)
RETURNING _id;
update:
@@ -120,5 +122,6 @@ SET manga_id = coalesce(:mangaId, manga_id),
date_fetch = coalesce(:dateFetch, date_fetch),
date_upload = coalesce(:dateUpload, date_upload),
version = coalesce(:version, version),
is_syncing = coalesce(:isSyncing, is_syncing)
is_syncing = coalesce(:isSyncing, is_syncing),
memo = coalesce(:memo, memo)
WHERE _id = :chapterId;
@@ -1,7 +1,8 @@
import eu.kanade.tachiyomi.source.model.UpdateStrategy;
import kotlin.collections.List;
import kotlin.Boolean;
import kotlin.String;
import kotlin.collections.List;
import kotlinx.serialization.json.JsonObject;
CREATE TABLE mangas(
_id INTEGER NOT NULL PRIMARY KEY,
@@ -28,7 +29,8 @@ CREATE TABLE mangas(
favorite_modified_at INTEGER,
version INTEGER NOT NULL DEFAULT 0,
is_syncing INTEGER NOT NULL DEFAULT 0,
notes TEXT NOT NULL DEFAULT ""
notes TEXT NOT NULL DEFAULT "",
memo BLOB AS JsonObject NOT NULL DEFAULT '{}'
);
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
@@ -194,8 +196,8 @@ AND (
);
insertReturningId:
INSERT INTO mangas(source, url, artist, author, description, genre, title, status, thumbnail_url, favorite, last_update, next_update, initialized, viewer, chapter_flags, cover_last_modified, date_added, update_strategy, calculate_interval, last_modified_at, version, notes)
VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded, :updateStrategy, :calculateInterval, 0, :version, :notes)
INSERT INTO mangas(source, url, artist, author, description, genre, title, status, thumbnail_url, favorite, last_update, next_update, initialized, viewer, chapter_flags, cover_last_modified, date_added, update_strategy, calculate_interval, last_modified_at, version, notes, memo)
VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded, :updateStrategy, :calculateInterval, 0, :version, :notes, :memo)
RETURNING _id;
update:
@@ -221,7 +223,8 @@ UPDATE mangas SET
calculate_interval = coalesce(:calculateInterval, calculate_interval),
version = coalesce(:version, version),
is_syncing = coalesce(:isSyncing, is_syncing),
notes = coalesce(:notes, notes)
notes = coalesce(:notes, notes),
memo = coalesce(:memo, memo)
WHERE _id = :mangaId;
insertNetworkManga {
@@ -229,12 +232,12 @@ insertNetworkManga {
INSERT INTO mangas(
source, url, artist, author, description, genre, title, status, thumbnail_url, favorite,
last_update, next_update, initialized, viewer, chapter_flags, cover_last_modified, date_added,
update_strategy, calculate_interval, last_modified_at, version
update_strategy, calculate_interval, last_modified_at, version, memo
)
SELECT
:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite,
:lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded,
:updateStrategy, :calculateInterval, 0, :version
:updateStrategy, :calculateInterval, 0, :version, :memo
WHERE NOT EXISTS(SELECT 0 FROM mangas WHERE source = :source AND url = :url);
-- Update the relevant details if applicable and not favorite
@@ -248,7 +251,8 @@ insertNetworkManga {
genre = CASE WHEN :updateDetails THEN :genre ELSE genre END,
status = CASE WHEN :updateDetails THEN :status ELSE status END,
update_strategy = CASE WHEN :updateDetails THEN :updateStrategy ELSE update_strategy END,
initialized = :updateDetails
initialized = :updateDetails,
memo = :memo
WHERE source = :source
AND url = :url
AND favorite = 0;
@@ -0,0 +1,2 @@
ALTER TABLE mangas ADD COLUMN memo BLOB NOT NULL DEFAULT '{}';
ALTER TABLE chapters ADD COLUMN memo BLOB NOT NULL DEFAULT '{}';