Remove unused sync scaffold

Drops the unused version, is_syncing and last_modified_at columns and their triggers.
This commit is contained in:
AntsyLich
2026-09-27 21:47:12 +06:00
parent 532575e29e
commit c67a33f3d4
18 changed files with 58 additions and 187 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ android {
defaultConfig {
applicationId = "app.mihon"
versionCode = 30
versionCode = 31
versionName = "0.20.4"
buildConfigField("boolean", "TELEMETRY_INCLUDED", "${Config.includeTelemetry}")
@@ -103,9 +103,7 @@ private fun Manga.toBackupManga() =
viewer_flags = this.viewerFlags.toInt(),
chapterFlags = this.chapterFlags.toInt(),
updateStrategy = this.updateStrategy,
lastModifiedAt = this.lastModifiedAt,
favoriteModifiedAt = this.favoriteModifiedAt,
version = this.version,
notes = this.notes,
initialized = this.initialized,
memo = MemoColumnAdapter.encode(this.memo),
@@ -23,8 +23,8 @@ class BackupChapter(
// chapterNumber is called number is 1.x
@ProtoNumber(9) var chapterNumber: Float = 0F,
@ProtoNumber(10) var sourceOrder: Long = 0,
@ProtoNumber(11) var lastModifiedAt: Long = 0,
@ProtoNumber(12) var version: Long = 0,
// @ProtoNumber(11) var lastModifiedAt: Long, artifact of the abandoned sync attempt
// @ProtoNumber(12) var version: Long, artifact of the abandoned sync attempt
@ProtoNumber(13) var memo: ByteArray = JsonObjectEmptyBytes,
) {
fun toChapterImpl(): Chapter {
@@ -39,8 +39,6 @@ class BackupChapter(
dateFetch = this@BackupChapter.dateFetch,
dateUpload = this@BackupChapter.dateUpload,
sourceOrder = this@BackupChapter.sourceOrder,
lastModifiedAt = this@BackupChapter.lastModifiedAt,
version = this@BackupChapter.version,
memo = MemoColumnAdapter.decode(this@BackupChapter.memo),
)
}
@@ -59,9 +57,6 @@ val backupChapterMapper = {
sourceOrder: Long,
dateFetch: Long,
dateUpload: Long,
lastModifiedAt: Long,
version: Long,
_: Long,
memo: JsonObject,
->
BackupChapter(
@@ -75,8 +70,6 @@ val backupChapterMapper = {
dateFetch = dateFetch,
dateUpload = dateUpload,
sourceOrder = sourceOrder,
lastModifiedAt = lastModifiedAt,
version = version,
memo = MemoColumnAdapter.encode(memo),
)
}
@@ -38,11 +38,11 @@ class BackupManga(
@ProtoNumber(103) var viewer_flags: Int? = null,
@ProtoNumber(104) var history: List<BackupHistory> = emptyList(),
@ProtoNumber(105) var updateStrategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE,
@ProtoNumber(106) var lastModifiedAt: Long = 0,
// @ProtoNumber(106) var lastModifiedAt: Long, artifact of the abandoned sync attempt
@ProtoNumber(107) var favoriteModifiedAt: Long? = null,
// Mihon values start here
@ProtoNumber(108) var excludedScanlators: List<String> = emptyList(),
@ProtoNumber(109) var version: Long = 0,
// @ProtoNumber(109) var version: Long, artifact of the abandoned sync attempt
@ProtoNumber(110) var notes: String = "",
@ProtoNumber(111) var initialized: Boolean = false,
@ProtoNumber(112) var memo: ByteArray = JsonObjectEmptyBytes,
@@ -63,9 +63,7 @@ class BackupManga(
viewerFlags = (this@BackupManga.viewer_flags ?: this@BackupManga.viewer).toLong(),
chapterFlags = this@BackupManga.chapterFlags.toLong(),
updateStrategy = this@BackupManga.updateStrategy,
lastModifiedAt = this@BackupManga.lastModifiedAt,
favoriteModifiedAt = this@BackupManga.favoriteModifiedAt,
version = this@BackupManga.version,
notes = this@BackupManga.notes,
initialized = this@BackupManga.initialized,
memo = MemoColumnAdapter.decode(this@BackupManga.memo),
@@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.backup.models.BackupManga
import eu.kanade.tachiyomi.data.backup.models.BackupTracking
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlinx.serialization.json.JsonObject
import tachiyomi.data.Database
import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
@@ -49,10 +50,7 @@ class MangaRestorer(
.groupBy({ it.source }, { it.url })
return backupMangas
.sortedWith(
compareBy<BackupManga> { it.url in urlsBySource[it.source].orEmpty() }
.then(compareByDescending { it.lastModifiedAt }),
)
.sortedBy { it.url in urlsBySource[it.source].orEmpty() }
}
suspend fun restore(
@@ -85,24 +83,26 @@ class MangaRestorer(
}
private suspend fun restoreExistingManga(manga: Manga, dbManga: Manga): Manga {
return if (manga.version > dbManga.version) {
updateManga(dbManga.copyFrom(manga).copy(id = dbManga.id))
} else {
updateManga(manga.copyFrom(dbManga).copy(id = dbManga.id))
}
}
private fun Manga.copyFrom(newer: Manga): Manga {
return this.copy(
favorite = this.favorite || newer.favorite,
author = newer.author,
artist = newer.artist,
description = newer.description,
genre = newer.genre,
thumbnailUrl = newer.thumbnailUrl,
status = newer.status,
initialized = this.initialized || newer.initialized,
version = newer.version,
val details = if (dbManga.initialized || !manga.initialized) dbManga else manga
return updateManga(
dbManga.copy(
favorite = dbManga.favorite || manga.favorite,
dateAdded = listOfNotNull(
dbManga.dateAdded.takeIf { it > 0 },
manga.dateAdded.takeIf { it > 0 },
).minOrNull() ?: 0L,
title = details.title,
artist = details.artist,
author = details.author,
description = details.description,
genre = details.genre,
status = details.status,
thumbnailUrl = details.thumbnailUrl,
updateStrategy = details.updateStrategy,
initialized = dbManga.initialized || manga.initialized,
// Merge both backup and local data with local winning
memo = JsonObject(manga.memo + dbManga.memo),
),
)
}
@@ -128,8 +128,6 @@ class MangaRestorer(
dateAdded = manga.dateAdded,
mangaId = manga.id,
updateStrategy = manga.updateStrategy,
version = manga.version,
isSyncing = 1,
notes = manga.notes,
memo = manga.memo,
)
@@ -161,24 +159,18 @@ class MangaRestorer(
return@mapNotNull null
}
// Update to an existing chapter
var updatedChapter = chapter
chapter
.copyFrom(dbChapter)
.copy(
id = dbChapter.id,
read = chapter.read || dbChapter.read,
bookmark = chapter.bookmark || dbChapter.bookmark,
lastPageRead = max(chapter.lastPageRead, dbChapter.lastPageRead),
dateFetch = dbChapter.dateFetch,
sourceOrder = dbChapter.sourceOrder,
// Merge both backup and local data with local winning
memo = JsonObject(chapter.memo + dbChapter.memo),
)
if (dbChapter.read && !updatedChapter.read) {
updatedChapter = updatedChapter.copy(
read = true,
lastPageRead = dbChapter.lastPageRead,
)
} else if (updatedChapter.lastPageRead == 0L && dbChapter.lastPageRead != 0L) {
updatedChapter = updatedChapter.copy(
lastPageRead = dbChapter.lastPageRead,
)
}
updatedChapter
}
.partition { it.id > 0 }
@@ -187,7 +179,7 @@ class MangaRestorer(
}
private fun Chapter.forComparison() =
this.copy(id = 0L, mangaId = 0L, dateFetch = 0L, dateUpload = 0L, lastModifiedAt = 0L, version = 0L)
this.copy(id = 0L, mangaId = 0L, dateFetch = 0L, dateUpload = 0L)
private suspend fun insertNewChapters(chapters: List<Chapter>) {
database.transaction {
@@ -204,7 +196,6 @@ class MangaRestorer(
chapter.sourceOrder,
chapter.dateFetch,
chapter.dateUpload,
chapter.version,
chapter.memo,
)
}
@@ -227,8 +218,6 @@ class MangaRestorer(
dateFetch = null,
dateUpload = null,
chapterId = chapter.id,
version = chapter.version,
isSyncing = 0,
memo = chapter.memo,
)
}
@@ -261,7 +250,6 @@ class MangaRestorer(
coverLastModified = manga.coverLastModified,
dateAdded = manga.dateAdded,
updateStrategy = manga.updateStrategy,
version = manga.version,
notes = manga.notes,
memo = manga.memo,
)
@@ -21,10 +21,6 @@ interface Chapter : SChapter, Serializable {
var date_fetch: Long
var source_order: Int
var last_modified: Long
var version: Long
}
val Chapter.isRecognizedNumber: Boolean
@@ -45,8 +41,6 @@ fun Chapter.toDomainChapter(): DomainChapter? {
dateUpload = date_upload,
chapterNumber = chapter_number.toDouble(),
scanlator = scanlator,
lastModifiedAt = last_modified,
version = version,
memo = memo,
)
}
@@ -31,10 +31,6 @@ class ChapterImpl : Chapter {
override var source_order: Int = 0
override var last_modified: Long = 0
override var version: Long = 0
override var memo: JsonObject = JsonObject.EMPTY
override fun equals(other: Any?): Boolean {
@@ -41,7 +41,6 @@ class ChapterRepositoryImpl(
chapter.sourceOrder,
chapter.dateFetch,
chapter.dateUpload,
chapter.version,
chapter.memo,
)
.awaitAsOne()
@@ -78,8 +77,6 @@ class ChapterRepositoryImpl(
dateFetch = chapterUpdate.dateFetch,
dateUpload = chapterUpdate.dateUpload,
chapterId = chapterUpdate.id,
version = chapterUpdate.version,
isSyncing = 0,
memo = chapterUpdate.memo,
)
}
@@ -150,9 +147,6 @@ class ChapterRepositoryImpl(
sourceOrder: Long,
dateFetch: Long,
dateUpload: Long,
lastModifiedAt: Long,
version: Long,
isSyncing: Long,
memo: JsonObject,
): Chapter = Chapter(
id = id,
@@ -167,8 +161,6 @@ class ChapterRepositoryImpl(
dateUpload = dateUpload,
chapterNumber = chapterNumber,
scanlator = scanlator,
lastModifiedAt = lastModifiedAt,
version = version,
memo = memo,
)
}
@@ -7,7 +7,6 @@ import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.MangaWithChapterCount
object MangaMapper {
@Suppress("UNUSED_PARAMETER")
fun mapManga(
id: Long,
source: Long,
@@ -29,10 +28,7 @@ object MangaMapper {
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
lastModifiedAt: Long,
favoriteModifiedAt: Long?,
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
): Manga = Manga(
@@ -56,9 +52,7 @@ object MangaMapper {
thumbnailUrl = thumbnailUrl,
updateStrategy = updateStrategy,
initialized = initialized,
lastModifiedAt = lastModifiedAt,
favoriteModifiedAt = favoriteModifiedAt,
version = version,
notes = notes,
memo = memo,
)
@@ -84,10 +78,7 @@ object MangaMapper {
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
lastModifiedAt: Long,
favoriteModifiedAt: Long?,
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
totalCount: Long,
@@ -119,10 +110,7 @@ object MangaMapper {
dateAdded,
updateStrategy,
calculateInterval,
lastModifiedAt,
favoriteModifiedAt,
version,
isSyncing,
notes,
memo,
),
@@ -156,10 +144,7 @@ object MangaMapper {
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
lastModifiedAt: Long,
favoriteModifiedAt: Long?,
version: Long,
isSyncing: Long,
notes: String,
memo: JsonObject,
totalCount: Long,
@@ -185,10 +170,7 @@ object MangaMapper {
dateAdded,
updateStrategy,
calculateInterval,
lastModifiedAt,
favoriteModifiedAt,
version,
isSyncing,
notes,
memo,
),
@@ -174,7 +174,6 @@ class MangaRepositoryImpl(
coverLastModified = it.coverLastModified,
dateAdded = it.dateAdded,
updateStrategy = it.updateStrategy,
version = it.version,
memo = it.memo,
updateTitle = it.title.isNotBlank(),
updateCover = !it.thumbnailUrl.isNullOrBlank(),
@@ -210,8 +209,6 @@ class MangaRepositoryImpl(
dateAdded = value.dateAdded,
mangaId = value.id,
updateStrategy = value.updateStrategy,
version = value.version,
isSyncing = 0,
notes = value.notes,
memo = value.memo,
)
@@ -14,9 +14,6 @@ CREATE TABLE chapters(
source_order INTEGER NOT NULL,
date_fetch INTEGER NOT NULL,
date_upload INTEGER NOT NULL,
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
@@ -26,30 +23,6 @@ CREATE INDEX chapters_manga_id_index ON chapters(manga_id);
CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0;
CREATE INDEX idx_chapters_url ON chapters(url);
CREATE TRIGGER update_last_modified_at_chapters
AFTER UPDATE ON chapters
FOR EACH ROW
BEGIN
UPDATE chapters
SET last_modified_at = strftime('%s', 'now')
WHERE _id = new._id;
END;
CREATE TRIGGER update_chapter_and_manga_version AFTER UPDATE ON chapters
WHEN new.is_syncing = 0 AND (
new.read != old.read OR
new.bookmark != old.bookmark OR
new.last_page_read != old.last_page_read
)
BEGIN
-- Update the chapter version
UPDATE chapters SET version = version + 1
WHERE _id = new._id;
-- Update the manga version
UPDATE mangas SET version = version + 1
WHERE _id = new.manga_id AND (SELECT is_syncing FROM mangas WHERE _id = new.manga_id) = 0;
END;
getChapterById:
SELECT *
@@ -95,18 +68,13 @@ removeChaptersWithIds:
DELETE FROM chapters
WHERE _id IN :chapterIds;
resetIsSyncing:
UPDATE chapters
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, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0, :memo);
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, :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, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, 0, :version, 0, :memo)
INSERT INTO chapters(manga_id, url, name, scanlator, read, bookmark, last_page_read, chapter_number, source_order, date_fetch, date_upload, memo)
VALUES (:mangaId, :url, :name, :scanlator, :read, :bookmark, :lastPageRead, :chapterNumber, :sourceOrder, :dateFetch, :dateUpload, :memo)
RETURNING _id;
update:
@@ -122,7 +90,5 @@ SET manga_id = coalesce(:mangaId, manga_id),
source_order = coalesce(:sourceOrder, source_order),
date_fetch = coalesce(:dateFetch, date_fetch),
date_upload = coalesce(:dateUpload, date_upload),
version = coalesce(:version, version),
is_syncing = coalesce(:isSyncing, is_syncing),
memo = coalesce(:memo, memo)
WHERE _id = :chapterId;
@@ -25,10 +25,7 @@ CREATE TABLE mangas(
date_added INTEGER NOT NULL,
update_strategy INTEGER AS UpdateStrategy NOT NULL DEFAULT 0,
calculate_interval INTEGER DEFAULT 0 NOT NULL,
last_modified_at INTEGER NOT NULL DEFAULT 0,
favorite_modified_at INTEGER,
version INTEGER NOT NULL DEFAULT 0,
is_syncing INTEGER NOT NULL DEFAULT 0,
notes TEXT NOT NULL DEFAULT "",
memo BLOB AS JsonObject NOT NULL DEFAULT '{}'
);
@@ -45,25 +42,6 @@ BEGIN
WHERE _id = new._id;
END;
CREATE TRIGGER update_last_modified_at_mangas
AFTER UPDATE ON mangas
FOR EACH ROW
BEGIN
UPDATE mangas
SET last_modified_at = strftime('%s', 'now')
WHERE _id = new._id;
END;
CREATE TRIGGER update_manga_version AFTER UPDATE ON mangas
BEGIN
UPDATE mangas SET version = version + 1
WHERE _id = new._id AND new.is_syncing = 0 AND (
new.url != old.url OR
new.description != old.description OR
new.favorite != old.favorite
);
END;
getMangaById:
SELECT *
FROM mangas
@@ -198,11 +176,6 @@ resetViewerFlags:
UPDATE mangas
SET viewer = 0;
resetIsSyncing:
UPDATE mangas
SET is_syncing = 0
WHERE is_syncing = 1;
getSourceIdsWithNonLibraryManga:
SELECT source, COUNT(*) AS manga_count
FROM mangas
@@ -224,8 +197,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, 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)
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, notes, memo)
VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded, :updateStrategy, :calculateInterval, :notes, :memo)
RETURNING _id;
update:
@@ -249,8 +222,6 @@ UPDATE mangas SET
date_added = coalesce(:dateAdded, date_added),
update_strategy = coalesce(:updateStrategy, update_strategy),
calculate_interval = coalesce(:calculateInterval, calculate_interval),
version = coalesce(:version, version),
is_syncing = coalesce(:isSyncing, is_syncing),
notes = coalesce(:notes, notes),
memo = coalesce(:memo, memo)
WHERE _id = :mangaId;
@@ -260,12 +231,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, memo
update_strategy, calculate_interval, memo
)
SELECT
:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite,
:lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded,
:updateStrategy, :calculateInterval, 0, :version, :memo
:updateStrategy, :calculateInterval, :memo
WHERE NOT EXISTS(SELECT 0 FROM mangas WHERE source = :source AND url = :url);
-- Update the relevant details if applicable and not favorite
@@ -11,13 +11,6 @@ CREATE TABLE mangas_categories(
CREATE INDEX idx_mangas_categories_manga_id ON mangas_categories(manga_id);
CREATE INDEX idx_mangas_categories_category_id ON mangas_categories(category_id);
CREATE TRIGGER insert_manga_category_update_version AFTER INSERT ON mangas_categories
BEGIN
UPDATE mangas
SET version = version + 1
WHERE _id = new.manga_id AND (SELECT is_syncing FROM mangas WHERE _id = new.manga_id) = 0;
END;
insert:
INSERT INTO mangas_categories(manga_id, category_id)
VALUES (:mangaId, :categoryId);
@@ -0,0 +1,15 @@
-- Remove the sync scaffolding: version, is_syncing and last_modified_at.
DROP TRIGGER update_manga_version;
DROP TRIGGER update_last_modified_at_mangas;
DROP TRIGGER update_chapter_and_manga_version;
DROP TRIGGER update_last_modified_at_chapters;
DROP TRIGGER insert_manga_category_update_version;
ALTER TABLE mangas DROP COLUMN version;
ALTER TABLE mangas DROP COLUMN is_syncing;
ALTER TABLE mangas DROP COLUMN last_modified_at;
ALTER TABLE chapters DROP COLUMN version;
ALTER TABLE chapters DROP COLUMN is_syncing;
ALTER TABLE chapters DROP COLUMN last_modified_at;
@@ -16,8 +16,6 @@ data class Chapter(
val dateUpload: Long,
val chapterNumber: Double,
val scanlator: String?,
val lastModifiedAt: Long,
val version: Long,
val memo: JsonObject,
) {
val isRecognizedNumber: Boolean
@@ -47,8 +45,6 @@ data class Chapter(
dateUpload = -1,
chapterNumber = -1.0,
scanlator = null,
lastModifiedAt = 0,
version = 1,
memo = JsonObject.EMPTY,
)
}
@@ -15,7 +15,6 @@ data class ChapterUpdate(
val dateUpload: Long? = null,
val chapterNumber: Double? = null,
val scanlator: String? = null,
val version: Long? = null,
val memo: JsonObject? = null,
)
@@ -33,7 +32,6 @@ fun Chapter.toChapterUpdate(): ChapterUpdate {
dateUpload,
chapterNumber,
scanlator,
version,
memo,
)
}
@@ -37,9 +37,7 @@ data class Manga(
val thumbnailUrl: String?,
val updateStrategy: UpdateStrategy,
val initialized: Boolean,
val lastModifiedAt: Long,
val favoriteModifiedAt: Long?,
val version: Long,
val notes: String,
val memo: JsonObject,
) : JavaSerializable {
@@ -133,9 +131,7 @@ data class Manga(
thumbnailUrl = null,
updateStrategy = UpdateStrategy.ALWAYS_UPDATE,
initialized = false,
lastModifiedAt = 0L,
favoriteModifiedAt = null,
version = 0L,
notes = "",
memo = JsonObject.EMPTY,
)
@@ -24,7 +24,6 @@ data class MangaUpdate(
val thumbnailUrl: String? = null,
val updateStrategy: UpdateStrategy? = null,
val initialized: Boolean? = null,
val version: Long? = null,
val notes: String? = null,
val memo: JsonObject? = null,
)
@@ -51,7 +50,6 @@ fun Manga.toMangaUpdate(): MangaUpdate {
thumbnailUrl = thumbnailUrl,
updateStrategy = updateStrategy,
initialized = initialized,
version = version,
notes = notes,
memo = memo,
)