mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user