From eeeb3b38dcddea0fd4230404a84ab72d1d04a7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartu=20=C3=96zen?= Date: Sat, 20 Dec 2025 19:34:11 +0300 Subject: [PATCH] Improvements --- .../tachidesk/global/impl/sync/SyncManager.kt | 20 ++++++++++--------- .../global/impl/sync/SyncYomiSyncService.kt | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncManager.kt index a76d6abea..55a66548d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncManager.kt @@ -36,8 +36,8 @@ import suwayomi.tachidesk.server.serverConfig import suwayomi.tachidesk.util.HAScheduler import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.util.Date import kotlin.system.measureTimeMillis +import kotlin.time.Clock import kotlin.time.Duration.Companion.minutes @Serializable @@ -92,9 +92,11 @@ object SyncManager { } GlobalScope.launch { - syncData() - }.invokeOnCompletion { - syncMutex.unlock() + try { + syncData() + } finally { + syncMutex.unlock() + } } return StartSyncResult.SUCCESS @@ -166,7 +168,7 @@ object SyncManager { // nothing changed logger.debug { "Skip restore due to remote was overwrite from local" } syncPreferences.edit() - .putLong("last_sync_timestamp", Date().time) + .putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds()) .apply() return } @@ -180,7 +182,7 @@ object SyncManager { if (syncPreferences.getLong("last_sync_timestamp", 0) == 0L && databaseManga.isNotEmpty()) { // It's first sync no need to restore data. (just update remote data) syncPreferences.edit() - .putLong("last_sync_timestamp", Date().time) + .putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds()) .apply() return } @@ -198,7 +200,7 @@ object SyncManager { if (filteredFavorites.isEmpty()) { // update the sync timestamp syncPreferences.edit() - .putLong("last_sync_timestamp", Date().time) + .putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds()) .apply() return } @@ -220,7 +222,7 @@ object SyncManager { // update the sync timestamp syncPreferences.edit() - .putLong("last_sync_timestamp", Date().time) + .putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds()) .apply() } @@ -363,7 +365,7 @@ object SyncManager { it[MangaTable.inLibrary] = manga.inLibrary it[MangaTable.inLibraryAt] = manga.inLibraryAt - it[MangaTable.sourceReference] = manga.sourceId.toLongOrNull() ?: 0L + it[MangaTable.sourceReference] = manga.sourceId.toLong() it[MangaTable.realUrl] = manga.realUrl it[MangaTable.lastFetchedAt] = manga.lastFetchedAt ?: 0L diff --git a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncYomiSyncService.kt b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncYomiSyncService.kt index 5bb2e2408..e3dd9685a 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncYomiSyncService.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/sync/SyncYomiSyncService.kt @@ -35,7 +35,7 @@ object SyncYomiSyncService { val (remoteData, etag) = pullSyncData() val finalSyncData = if (remoteData != null) { - assert(etag.isNotEmpty()) { "ETag should never be empty if remote data is not null" } + require(etag.isNotEmpty()) { "ETag should never be empty if remote data is not null" } logger.debug { "Try update remote data with ETag($etag)" } mergeSyncData(syncData, remoteData) } else { @@ -74,7 +74,7 @@ object SyncYomiSyncService { if (response.code == HttpStatus.NOT_MODIFIED.code) { // not modified - assert(lastETag.isNotEmpty()) + require(lastETag.isNotEmpty()) logger.info { "Remote server not modified" } return Pair(null, lastETag) } else if (response.code == HttpStatus.NOT_FOUND.code) { @@ -84,7 +84,7 @@ object SyncYomiSyncService { if (response.isSuccessful) { val newETag = response.headers["ETag"] - .takeIf { it?.isNotEmpty() == true } ?: throw SyncYomiException("Missing ETag") + ?.takeIf { it.isNotEmpty() } ?: throw SyncYomiException("Missing ETag") val byteArray = response.body.byteStream().use { return@use it.readBytes() @@ -143,7 +143,7 @@ object SyncYomiSyncService { if (response.isSuccessful) { val newETag = response.headers["ETag"] - .takeIf { it?.isNotEmpty() == true } ?: throw SyncYomiException("Missing ETag") + ?.takeIf { it.isNotEmpty() } ?: throw SyncYomiException("Missing ETag") syncPreferences.edit() .putString("last_sync_etag", newETag) .apply()