mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
Add periodic sync
This commit is contained in:
@@ -1072,6 +1072,13 @@ class ServerConfig(
|
||||
privacySafe = true,
|
||||
)
|
||||
|
||||
val syncInterval: MutableStateFlow<Int> by IntSetting(
|
||||
protoNumber = 94,
|
||||
defaultValue = 0,
|
||||
group = SettingGroup.SYNCYOMI,
|
||||
privacySafe = true,
|
||||
)
|
||||
|
||||
/** ****************************************************************** **/
|
||||
/** **/
|
||||
/** Renamed settings **/
|
||||
|
||||
@@ -3,6 +3,10 @@ package suwayomi.tachidesk.global.impl.sync
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
@@ -26,10 +30,12 @@ import suwayomi.tachidesk.manga.model.table.MangaStatus
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
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.Duration.Companion.minutes
|
||||
|
||||
@Serializable
|
||||
data class SyncData(
|
||||
@@ -40,6 +46,33 @@ object SyncManager {
|
||||
private val syncPreferences = Injekt.get<Application>().getSharedPreferences("sync", Context.MODE_PRIVATE)
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun scheduleSyncTask() {
|
||||
serverConfig.subscribeTo(
|
||||
combine(
|
||||
serverConfig.syncYomiEnabled,
|
||||
serverConfig.syncInterval,
|
||||
) { enabled, interval -> Pair(enabled, interval) },
|
||||
{ (enabled, interval) ->
|
||||
if (enabled && interval > 0) {
|
||||
val intervalMs = interval.minutes.inWholeMilliseconds
|
||||
|
||||
HAScheduler.schedule(
|
||||
{
|
||||
GlobalScope.launch {
|
||||
syncData()
|
||||
}
|
||||
},
|
||||
interval = intervalMs,
|
||||
delay = intervalMs,
|
||||
name = "sync",
|
||||
)
|
||||
}
|
||||
},
|
||||
ignoreInitialValue = false,
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun syncData() {
|
||||
transaction {
|
||||
MangaTable.update({ MangaTable.isSyncing eq true }) {
|
||||
@@ -56,7 +89,7 @@ object SyncManager {
|
||||
includeManga = serverConfig.syncDataManga.value,
|
||||
includeCategories = serverConfig.syncDataCategories.value,
|
||||
includeChapters = serverConfig.syncDataChapters.value,
|
||||
includeTracking = serverConfig.syncDataTracking.value,
|
||||
includeTracking = serverConfig.syncDataTracking.value,
|
||||
includeHistory = serverConfig.syncDataHistory.value,
|
||||
includeClientData = false,
|
||||
includeServerSettings = false,
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.koin.core.context.startKoin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
import suwayomi.tachidesk.global.impl.KcefWebView.Companion.toCefCookie
|
||||
import suwayomi.tachidesk.global.impl.sync.SyncManager
|
||||
import suwayomi.tachidesk.graphql.types.DatabaseType
|
||||
import suwayomi.tachidesk.i18n.LocalizationHelper
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupExport
|
||||
@@ -511,6 +512,8 @@ fun applicationSetup() {
|
||||
// start DownloadManager and restore + resume downloads
|
||||
DownloadManager.restoreAndResumeDownloads()
|
||||
|
||||
SyncManager.scheduleSyncTask()
|
||||
|
||||
GlobalScope.launch {
|
||||
val logger = KotlinLogging.logger("KCEF")
|
||||
KCEF.init(
|
||||
|
||||
Reference in New Issue
Block a user