mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
Sync before library update
This commit is contained in:
@@ -8,6 +8,7 @@ import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
@@ -99,6 +100,24 @@ object SyncManager {
|
||||
return StartSyncResult.SUCCESS
|
||||
}
|
||||
|
||||
suspend fun ensureSync() {
|
||||
if (!serverConfig.syncYomiEnabled.value) {
|
||||
return
|
||||
}
|
||||
|
||||
if (syncMutex.tryLock()) {
|
||||
// there is no ongoing sync, so start one
|
||||
try {
|
||||
syncData()
|
||||
} finally {
|
||||
syncMutex.unlock()
|
||||
}
|
||||
} else {
|
||||
// wait for the ongoing sync to finish
|
||||
syncMutex.withLock {}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun syncData() {
|
||||
transaction {
|
||||
MangaTable.update({ MangaTable.isSyncing eq true }) {
|
||||
|
||||
@@ -26,8 +26,10 @@ import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import suwayomi.tachidesk.global.impl.sync.SyncManager
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
@@ -337,6 +339,10 @@ class Updater : IUpdater {
|
||||
clear: Boolean?,
|
||||
forceAll: Boolean,
|
||||
) {
|
||||
runBlocking {
|
||||
SyncManager.ensureSync()
|
||||
}
|
||||
|
||||
saveLastUpdateTimestamp()
|
||||
|
||||
if (clear == true) {
|
||||
|
||||
Reference in New Issue
Block a user