Feature/backup suwayomi data (#1430)

* Export meta data

* Import meta data

* Add missing "opdsUseBinaryFileSize" setting to gql

* Export server settings

* Import server settings

* Streamline server config enum handling

* Use "restore amount" in backup import progress
This commit is contained in:
schroda
2025-06-15 23:14:13 +02:00
committed by GitHub
parent 483e3a760f
commit 4086a73727
29 changed files with 662 additions and 155 deletions

View File

@@ -1,9 +1,10 @@
package suwayomi.tachidesk.global.impl
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.statements.BatchUpdateStatement
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.global.model.table.GlobalMetaTable
/*
@@ -18,20 +19,32 @@ object GlobalMeta {
key: String,
value: String,
) {
transaction {
val meta =
transaction {
GlobalMetaTable.selectAll().where { GlobalMetaTable.key eq key }
}.firstOrNull()
modifyMetas(mapOf(key to value))
}
if (meta == null) {
GlobalMetaTable.insert {
it[GlobalMetaTable.key] = key
it[GlobalMetaTable.value] = value
fun modifyMetas(meta: Map<String, String>) {
transaction {
val dbMetaMap =
GlobalMetaTable
.selectAll()
.where { GlobalMetaTable.key inList meta.keys }
.associateBy { it[GlobalMetaTable.key] }
val (existingMeta, newMeta) = meta.toList().partition { (key) -> key in dbMetaMap.keys }
if (existingMeta.isNotEmpty()) {
BatchUpdateStatement(GlobalMetaTable).apply {
existingMeta.forEach { (key, value) ->
addBatch(EntityID(dbMetaMap[key]!![GlobalMetaTable.id].value, GlobalMetaTable))
this[GlobalMetaTable.value] = value
}
execute(this@transaction)
}
} else {
GlobalMetaTable.update({ GlobalMetaTable.key eq key }) {
it[GlobalMetaTable.value] = value
}
if (newMeta.isNotEmpty()) {
GlobalMetaTable.batchInsert(newMeta) { (key, value) ->
this[GlobalMetaTable.key] = key
this[GlobalMetaTable.value] = value
}
}
}