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