Improve performance

This commit is contained in:
Potatoboy9999 2022-06-14 12:09:37 -07:00
parent a767a78fc1
commit 92f9a172d1
No known key found for this signature in database
GPG Key ID: 59B6B6930BF7F2AB
4 changed files with 66 additions and 8 deletions

View File

@ -34,10 +34,12 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Yes this has to be capitalised
modImplementation "com.github.quiltservertools:ledger:1.2.0"
modImplementation "com.github.quiltservertools:Ledger:1.2.5"
modImplementation "net.fabricmc:fabric-language-kotlin:1.7.0+kotlin.1.6.0"
implementation(include("com.zaxxer:HikariCP:5.0.1"))
// H2
implementation(include("com.h2database:h2:1.4.200"))
@ -79,7 +81,13 @@ jar {
publishing {
publications {
mavenJava(MavenPublication) {
from(components["java"])
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}

View File

@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.2
loader_version=0.12.11
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.12.5
# Mod Properties
mod_version = 1.1.1
mod_version = 1.0.2
maven_group = net.quiltservertools
archives_base_name = ledger-databases

View File

@ -0,0 +1,50 @@
package net.quiltservertools.ledger.databases
import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.api.DatabaseExtension
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import net.minecraft.util.Identifier
import org.h2.jdbcx.JdbcDataSource
import org.sqlite.SQLiteDataSource
import java.nio.file.Path
import javax.sql.DataSource
import kotlin.io.path.pathString
class LedgerDatabaseExtension : DatabaseExtension {
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
override fun getDataSource(fileLocation: Path): DataSource {
return when (Ledger.config[DatabaseExtensionSpec.database]) {
Databases.SQLITE -> SQLiteDataSource().apply {
url = "jdbc:sqlite:${fileLocation.resolve("ledger.sqlite").pathString}"
}
Databases.H2 -> JdbcDataSource().apply {
setURL("jdbc:h2:${fileLocation.resolve("ledger.h2").pathString};MODE=MySQL")
}
Databases.MYSQL -> HikariDataSource(HikariConfig().apply {
jdbcUrl = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
username = Ledger.config[DatabaseExtensionSpec.userName]
password = Ledger.config[DatabaseExtensionSpec.password]
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
})
Databases.POSTGRESQL -> HikariDataSource(HikariConfig().apply {
jdbcUrl = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
username = Ledger.config[DatabaseExtensionSpec.userName]
password = Ledger.config[DatabaseExtensionSpec.password]
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
})
}
}
override fun getIdentifier(): Identifier = when (Ledger.config[DatabaseExtensionSpec.database]) {
Databases.MYSQL -> Ledger.identifier("mysql_extension")
Databases.H2 -> Ledger.identifier("h2_extension")
Databases.POSTGRESQL -> Ledger.identifier("postgresql_extension")
else -> Ledger.identifier(Ledger.DEFAULT_DATABASE)
}
}

View File

@ -7,5 +7,5 @@ object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
val userName by optional("root", "username")
val password by optional("", "password")
val url by optional("localhost", "url")
val properties by optional(listOf<String>(), "properties")
val maxPoolSize by optional(10, "maxPoolSize")
}