Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into 1.20.5
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt
  • Loading branch information
PotatoPresident committed Jun 1, 2024
2 parents 5ccded5 + d62c25f commit cd72e28
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 112 deletions.
15 changes: 14 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ Found under `[database]`

`queueTimeoutMin` [Default: 5] is the maximum amount of time to wait for the queue to drain when the server stops in minutes

`queueCheckDelaySec` [Default: 10] is the amount of time between checking if the queue is empty when the server stops in seconds
`queueCheckDelaySec` [Default: 10] is the frequency in seconds to notify in console that the queue is not empty when the server stops

`autoPurgeDays` [Default: -1] is the number of days to keep actions in the database. If set to -1, actions will never be purged automatically

`batchSize` [Default: 1000] is the number of actions to insert into the database at once.
This can be increased to improve performance, but may cause issues with slow databases

`batchDelay` [Default: 10] is the amount of time in ticks to wait between batches if the next batch isn't full.
This can be increased to improve performance, but may cause issues with slow databases

`location` [Default: Nothing] is the location of the database file when using the default SQLite database or other file based databases like H2.
The path is relative to the server's root directory. If the path is left out, the database will default to the server's world directory.

`logSQL` [Default: false] will log all SQL queries to the console. This is useful for debugging, but can be very spammy

### Search settings

Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ properties = []
`url`: Must be URL of database with `/<database_name>` appended. An example URL would be `localhost/ledger`. You can optionally add port information such as `localhost:3000/ledger`

### PostgreSQL
MySQL requires running a separate PostgreSQL database and more setup than just plug and play SQLite, but can support much larger databases at faster speeds. It is more experimental the MySQL but may yield faster performance.
PostgreSQL requires running a separate PostgreSQL database and more setup than just plug and play SQLite, but can support much larger databases at faster speeds. It is more experimental the MySQL but may yield faster performance.

Add the following to the bottom of your Ledger config file:

Expand Down
2 changes: 1 addition & 1 deletion docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ An easy way to remember the difference between `before:1d` and `after:1d` is to
If you go back in time 1 day, do you want everything that happened `before` then or `after` then.
Usually you want `after`.

### Rollback Status
## Rollback Status
Key - `rolledback:`
Value - `true` or `false`
Negative Allowed - `No`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.quiltservertools.ledger.api

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.config.config
import com.github.quiltservertools.ledger.config.getDatabasePath
import net.minecraft.server.MinecraftServer
import net.minecraft.util.WorldSavePath
import javax.sql.DataSource

object ExtensionManager {
Expand All @@ -30,7 +30,7 @@ object ExtensionManager {
extensions.forEach {
if (it is DatabaseExtension) {
if (dataSource == null) {
dataSource = it.getDataSource(server.getSavePath(WorldSavePath.ROOT))
dataSource = it.getDataSource(config.getDatabasePath())
} else {
failExtensionRegistration(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.minecraft.util.math.BlockBox
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3i
import java.time.Instant
import java.util.*
import java.util.concurrent.CompletableFuture

object SearchParamArgument {
Expand Down Expand Up @@ -140,7 +141,8 @@ object SearchParamArgument {
}
} else {
val profile = source.server.userCache?.findByName(sourceInput.property)
val id = profile?.orElse(null)?.id
// If the player doesn't exist use a random UUID to make the query not match
val id = profile?.orElse(null)?.id ?: UUID.randomUUID()

if (id != null) {
val playerIdEntry = Negatable(id, sourceInput.allowed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ class SourceParameter : SimpleParameter<String>() {
val stringReader = StringReader(builder.input)
stringReader.cursor = builder.start

val players = context.source.playerNames
val sources = context.source.playerNames
DatabaseManager.getKnownSources().forEach {
players.add("@$it")
sources.add("@$it")
}
// TODO suggest non-player sources

return CommandSource.suggestMatching(
players,
sources,
builder
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.quiltservertools.ledger.config

import com.github.quiltservertools.ledger.Ledger
import com.uchuhimo.konf.Config
import com.uchuhimo.konf.ConfigSpec
import net.minecraft.util.WorldSavePath
import java.nio.file.Path

@Suppress("MagicNumber")
object DatabaseSpec : ConfigSpec() {
Expand All @@ -10,4 +14,14 @@ object DatabaseSpec : ConfigSpec() {
val batchSize by optional<Int>(1000)
val batchDelay by optional<Int>(10)
val logSQL by optional<Boolean>(false)
val location by optional<String?>(null)
}

fun Config.getDatabasePath(): Path {
val location = config[DatabaseSpec.location]
return if (location != null) {
Path.of(location)
} else {
Ledger.server.getSavePath(WorldSavePath.ROOT)
}
}
Loading

0 comments on commit cd72e28

Please sign in to comment.