Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database optimize #291

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
8 changes: 4 additions & 4 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
minecraft = "1.21"
yarn-mappings = "1.21+build.1"
fabric-loader = "0.15.11"
yarn-mappings = "1.21+build.9"
fabric-loader = "0.16.5"

fabric-api = "0.100.1+1.21"
fabric-api = "0.102.0+1.21"

# Kotlin
kotlin = "2.0.0"
Expand Down Expand Up @@ -48,7 +48,7 @@ wdmcf = { module = "me.bymartrixx:wdmcf", version.ref = "wdmcf" }
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detect" }
loom = { id = "fabric-loom", version = "1.6.+" }
loom = { id = "fabric-loom", version = "1.7.3" }
git_hooks = { id = "com.github.jakemarsden.git-hooks", version = "0.0.2" }
# https://github.com/johnrengelman/shadow/issues/894
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.quiltservertools.ledger.commands

import com.github.quiltservertools.ledger.api.ExtensionManager
import com.github.quiltservertools.ledger.commands.subcommands.ConvertSubcommand
import com.github.quiltservertools.ledger.commands.subcommands.InspectCommand
import com.github.quiltservertools.ledger.commands.subcommands.PageCommand
import com.github.quiltservertools.ledger.commands.subcommands.PlayerCommand
Expand Down Expand Up @@ -53,6 +54,8 @@ fun registerCommands(dispatcher: Dispatcher) {

rootNode.addChild(PlayerCommand.build())

rootNode.addChild(ConvertSubcommand.build())

ExtensionManager.commands.forEach {
it.registerSubcommands().forEach { command ->
rootNode.addChild(command.build())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.quiltservertools.ledger.commands.subcommands

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.commands.BuildableCommand
import com.github.quiltservertools.ledger.commands.CommandConsts
import com.github.quiltservertools.ledger.database.DatabaseManager
import com.github.quiltservertools.ledger.utility.LiteralNode
import com.mojang.brigadier.context.CommandContext
import kotlinx.coroutines.launch
import me.lucko.fabric.api.permissions.v0.Permissions
import net.minecraft.server.command.CommandManager.literal
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text

private const val PROGRESS_INTERVAL = 30L

object ConvertSubcommand : BuildableCommand {
override fun build(): LiteralNode =
literal("convert")
.requires(Permissions.require("ledger.commands.convert", CommandConsts.PERMISSION_LEVEL))
.executes { convertDatabase(it) }
.build()

private fun convertDatabase(it: CommandContext<ServerCommandSource>): Int {
Ledger.launch {
DatabaseManager.convertActions { done, total ->
if (done % PROGRESS_INTERVAL == 0L) {
it.source.sendFeedback({ Text.of("Converted $done/$total actions") }, false)
}
}
}
return 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ object DatabaseSpec : ConfigSpec() {
val queueTimeoutMin by required<Long>()
val queueCheckDelaySec by required<Long>()
val autoPurgeDays by required<Int>()
val smartPurge by optional<Boolean>(false)
val smartPurgeThreshold by optional<Int>(100)
val smartPurgeFilter by optional<List<String>>(
listOf(
"action_id",
"world_id",
"x",
"y",
"z",
"object_id",
"player_id"
)
)
val batchSize by optional<Int>(1000)
val batchDelay by optional<Int>(10)
val logSQL by optional<Boolean>(false)
Expand Down
Loading