mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 02:44:34 -05:00
Improvements
This commit is contained in:
@@ -36,8 +36,8 @@ import suwayomi.tachidesk.server.serverConfig
|
|||||||
import suwayomi.tachidesk.util.HAScheduler
|
import suwayomi.tachidesk.util.HAScheduler
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.Date
|
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
import kotlin.time.Clock
|
||||||
import kotlin.time.Duration.Companion.minutes
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -92,9 +92,11 @@ object SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
syncData()
|
try {
|
||||||
}.invokeOnCompletion {
|
syncData()
|
||||||
syncMutex.unlock()
|
} finally {
|
||||||
|
syncMutex.unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return StartSyncResult.SUCCESS
|
return StartSyncResult.SUCCESS
|
||||||
@@ -166,7 +168,7 @@ object SyncManager {
|
|||||||
// nothing changed
|
// nothing changed
|
||||||
logger.debug { "Skip restore due to remote was overwrite from local" }
|
logger.debug { "Skip restore due to remote was overwrite from local" }
|
||||||
syncPreferences.edit()
|
syncPreferences.edit()
|
||||||
.putLong("last_sync_timestamp", Date().time)
|
.putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds())
|
||||||
.apply()
|
.apply()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -180,7 +182,7 @@ object SyncManager {
|
|||||||
if (syncPreferences.getLong("last_sync_timestamp", 0) == 0L && databaseManga.isNotEmpty()) {
|
if (syncPreferences.getLong("last_sync_timestamp", 0) == 0L && databaseManga.isNotEmpty()) {
|
||||||
// It's first sync no need to restore data. (just update remote data)
|
// It's first sync no need to restore data. (just update remote data)
|
||||||
syncPreferences.edit()
|
syncPreferences.edit()
|
||||||
.putLong("last_sync_timestamp", Date().time)
|
.putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds())
|
||||||
.apply()
|
.apply()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -198,7 +200,7 @@ object SyncManager {
|
|||||||
if (filteredFavorites.isEmpty()) {
|
if (filteredFavorites.isEmpty()) {
|
||||||
// update the sync timestamp
|
// update the sync timestamp
|
||||||
syncPreferences.edit()
|
syncPreferences.edit()
|
||||||
.putLong("last_sync_timestamp", Date().time)
|
.putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds())
|
||||||
.apply()
|
.apply()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -220,7 +222,7 @@ object SyncManager {
|
|||||||
|
|
||||||
// update the sync timestamp
|
// update the sync timestamp
|
||||||
syncPreferences.edit()
|
syncPreferences.edit()
|
||||||
.putLong("last_sync_timestamp", Date().time)
|
.putLong("last_sync_timestamp", Clock.System.now().toEpochMilliseconds())
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +365,7 @@ object SyncManager {
|
|||||||
it[MangaTable.inLibrary] = manga.inLibrary
|
it[MangaTable.inLibrary] = manga.inLibrary
|
||||||
it[MangaTable.inLibraryAt] = manga.inLibraryAt
|
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.realUrl] = manga.realUrl
|
||||||
it[MangaTable.lastFetchedAt] = manga.lastFetchedAt ?: 0L
|
it[MangaTable.lastFetchedAt] = manga.lastFetchedAt ?: 0L
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ object SyncYomiSyncService {
|
|||||||
val (remoteData, etag) = pullSyncData()
|
val (remoteData, etag) = pullSyncData()
|
||||||
|
|
||||||
val finalSyncData = if (remoteData != null) {
|
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)" }
|
logger.debug { "Try update remote data with ETag($etag)" }
|
||||||
mergeSyncData(syncData, remoteData)
|
mergeSyncData(syncData, remoteData)
|
||||||
} else {
|
} else {
|
||||||
@@ -74,7 +74,7 @@ object SyncYomiSyncService {
|
|||||||
|
|
||||||
if (response.code == HttpStatus.NOT_MODIFIED.code) {
|
if (response.code == HttpStatus.NOT_MODIFIED.code) {
|
||||||
// not modified
|
// not modified
|
||||||
assert(lastETag.isNotEmpty())
|
require(lastETag.isNotEmpty())
|
||||||
logger.info { "Remote server not modified" }
|
logger.info { "Remote server not modified" }
|
||||||
return Pair(null, lastETag)
|
return Pair(null, lastETag)
|
||||||
} else if (response.code == HttpStatus.NOT_FOUND.code) {
|
} else if (response.code == HttpStatus.NOT_FOUND.code) {
|
||||||
@@ -84,7 +84,7 @@ object SyncYomiSyncService {
|
|||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val newETag = response.headers["ETag"]
|
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 {
|
val byteArray = response.body.byteStream().use {
|
||||||
return@use it.readBytes()
|
return@use it.readBytes()
|
||||||
@@ -143,7 +143,7 @@ object SyncYomiSyncService {
|
|||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val newETag = response.headers["ETag"]
|
val newETag = response.headers["ETag"]
|
||||||
.takeIf { it?.isNotEmpty() == true } ?: throw SyncYomiException("Missing ETag")
|
?.takeIf { it.isNotEmpty() } ?: throw SyncYomiException("Missing ETag")
|
||||||
syncPreferences.edit()
|
syncPreferences.edit()
|
||||||
.putString("last_sync_etag", newETag)
|
.putString("last_sync_etag", newETag)
|
||||||
.apply()
|
.apply()
|
||||||
|
|||||||
Reference in New Issue
Block a user