Merge manga favorite related fields into favorite_at

Migration 16 replaces favorite, date_added and favorite_modified_at with one nullable favorite_at. A favorite whose date_added is 0 falls back to favorite_modified_at. Manga.favorite and dateAdded become getters derived from it, and restore merges it by taking the earliest non-zero time.
This commit is contained in:
AntsyLich
2026-09-27 22:37:02 +06:00
parent f8fff318ba
commit 986f46c09a
18 changed files with 183 additions and 109 deletions
@@ -72,11 +72,11 @@ class RestoreRepositoryImpl(
private fun mergeManga(manga: Manga, dbManga: Manga): Manga {
val details = if (dbManga.initialized || !manga.initialized) dbManga else manga
return dbManga.copy(
favorite = dbManga.favorite || manga.favorite,
dateAdded = listOfNotNull(
dbManga.dateAdded.takeIf { it > 0 },
manga.dateAdded.takeIf { it > 0 },
).minOrNull() ?: 0L,
favoriteAt = if (dbManga.favorite || manga.favorite) {
listOfNotNull(dbManga.favoriteAt, manga.favoriteAt).filter { it > 0 }.minOrNull() ?: 0L
} else {
null
},
title = details.title,
artist = details.artist,
author = details.author,
@@ -93,6 +93,7 @@ class RestoreRepositoryImpl(
private suspend fun updateManga(manga: Manga): Manga {
database.mangasQueries.updateFromBackup(
favoriteAt = manga.favoriteAt,
artist = manga.artist,
author = manga.author,
description = manga.description,
@@ -100,13 +101,11 @@ class RestoreRepositoryImpl(
title = manga.title,
status = manga.status,
thumbnailUrl = manga.thumbnailUrl,
favorite = manga.favorite,
lastUpdate = manga.lastUpdate,
initialized = manga.initialized,
viewer = manga.viewerFlags,
chapterFlags = manga.chapterFlags,
coverLastModified = manga.coverLastModified,
dateAdded = manga.dateAdded,
mangaId = manga.id,
updateStrategy = manga.updateStrategy,
notes = manga.notes,
@@ -117,6 +116,7 @@ class RestoreRepositoryImpl(
private suspend fun insertManga(manga: Manga): Long {
return database.mangasQueries.insertReturningId(
favoriteAt = manga.favoriteAt,
source = manga.source,
url = manga.url,
artist = manga.artist,
@@ -126,7 +126,6 @@ class RestoreRepositoryImpl(
title = manga.title,
status = manga.status,
thumbnailUrl = manga.thumbnailUrl,
favorite = manga.favorite,
lastUpdate = manga.lastUpdate,
nextUpdate = 0L,
calculateInterval = 0L,
@@ -134,7 +133,6 @@ class RestoreRepositoryImpl(
viewerFlags = manga.viewerFlags,
chapterFlags = manga.chapterFlags,
coverLastModified = manga.coverLastModified,
dateAdded = manga.dateAdded,
updateStrategy = manga.updateStrategy,
notes = manga.notes,
memo = manga.memo,
@@ -18,27 +18,24 @@ object MangaMapper {
title: String,
status: Long,
thumbnailUrl: String?,
favorite: Boolean,
lastUpdate: Long?,
nextUpdate: Long?,
initialized: Boolean,
viewerFlags: Long,
chapterFlags: Long,
coverLastModified: Long,
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
favoriteModifiedAt: Long?,
notes: String,
memo: JsonObject,
favoriteAt: Long?,
): Manga = Manga(
id = id,
source = source,
favorite = favorite,
lastUpdate = lastUpdate ?: 0,
nextUpdate = nextUpdate ?: 0,
fetchInterval = calculateInterval.toInt(),
dateAdded = dateAdded,
favoriteAt = favoriteAt,
viewerFlags = viewerFlags,
chapterFlags = chapterFlags,
coverLastModified = coverLastModified,
@@ -52,7 +49,6 @@ object MangaMapper {
thumbnailUrl = thumbnailUrl,
updateStrategy = updateStrategy,
initialized = initialized,
favoriteModifiedAt = favoriteModifiedAt,
notes = notes,
memo = memo,
)
@@ -68,19 +64,17 @@ object MangaMapper {
title: String,
status: Long,
thumbnailUrl: String?,
favorite: Boolean,
lastUpdate: Long?,
nextUpdate: Long?,
initialized: Boolean,
viewerFlags: Long,
chapterFlags: Long,
coverLastModified: Long,
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
favoriteModifiedAt: Long?,
notes: String,
memo: JsonObject,
favoriteAt: Long?,
totalCount: Long,
readCount: Double,
latestUpload: Long,
@@ -100,19 +94,17 @@ object MangaMapper {
title,
status,
thumbnailUrl,
favorite,
lastUpdate,
nextUpdate,
initialized,
viewerFlags,
chapterFlags,
coverLastModified,
dateAdded,
updateStrategy,
calculateInterval,
favoriteModifiedAt,
notes,
memo,
favoriteAt,
),
categories = categories.split(",").map { it.toLong() },
totalChapters = totalCount,
@@ -134,19 +126,17 @@ object MangaMapper {
title: String,
status: Long,
thumbnailUrl: String?,
favorite: Boolean,
lastUpdate: Long?,
nextUpdate: Long?,
initialized: Boolean,
viewerFlags: Long,
chapterFlags: Long,
coverLastModified: Long,
dateAdded: Long,
updateStrategy: UpdateStrategy,
calculateInterval: Long,
favoriteModifiedAt: Long?,
notes: String,
memo: JsonObject,
favoriteAt: Long?,
totalCount: Long,
): MangaWithChapterCount = MangaWithChapterCount(
manga = mapManga(
@@ -160,19 +150,17 @@ object MangaMapper {
title,
status,
thumbnailUrl,
favorite,
lastUpdate,
nextUpdate,
initialized,
viewerFlags,
chapterFlags,
coverLastModified,
dateAdded,
updateStrategy,
calculateInterval,
favoriteModifiedAt,
notes,
memo,
favoriteAt,
),
chapterCount = totalCount,
)
@@ -198,7 +198,7 @@ class MangaRepositoryImpl(
title = it.title,
status = it.status,
thumbnailUrl = it.thumbnailUrl,
favorite = it.favorite,
favoriteAt = it.favoriteAt,
lastUpdate = it.lastUpdate,
nextUpdate = it.nextUpdate,
calculateInterval = it.fetchInterval.toLong(),
@@ -206,7 +206,6 @@ class MangaRepositoryImpl(
viewerFlags = it.viewerFlags,
chapterFlags = it.chapterFlags,
coverLastModified = it.coverLastModified,
dateAdded = it.dateAdded,
updateStrategy = it.updateStrategy,
memo = it.memo,
updateTitle = it.title.isNotBlank(),
@@ -247,14 +246,14 @@ class MangaRepositoryImpl(
mangaUpdates.forEach { value ->
with(value) {
database.mangasQueries.update(
favorite = favorite,
favoriteAtSet = isSet(::favoriteAt),
favoriteAt = favoriteAt,
lastUpdate = lastUpdate,
nextUpdate = nextUpdate,
calculateInterval = fetchInterval?.toLong(),
viewer = viewerFlags,
chapterFlags = chapterFlags,
coverLastModified = coverLastModified,
dateAdded = dateAdded,
mangaId = id,
notes = notes,
)