From 92f9a172d1976263e5aa5cf94c0b0a15e86f1215 Mon Sep 17 00:00:00 2001 From: Potatoboy9999 <51728317+PotatoPresident@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:09:37 -0700 Subject: [PATCH] Improve performance --- build.gradle | 12 ++++- gradle.properties | 8 +-- .../LedgerDatabaseExtension.kt | 50 +++++++++++++++++++ .../ledger/databases/DatabaseExtensionSpec.kt | 4 +- 4 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/net.quiltservertools.ledger.databases/LedgerDatabaseExtension.kt diff --git a/build.gradle b/build.gradle index 5f2ceff..e0c3620 100644 --- a/build.gradle +++ b/build.gradle @@ -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 + } } } diff --git a/gradle.properties b/gradle.properties index 185a204..5c810ed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/net.quiltservertools.ledger.databases/LedgerDatabaseExtension.kt b/src/main/kotlin/net.quiltservertools.ledger.databases/LedgerDatabaseExtension.kt new file mode 100644 index 0000000..b6dc1f5 --- /dev/null +++ b/src/main/kotlin/net.quiltservertools.ledger.databases/LedgerDatabaseExtension.kt @@ -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 = 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) + } +} diff --git a/src/main/kotlin/net/quiltservertools/ledger/databases/DatabaseExtensionSpec.kt b/src/main/kotlin/net/quiltservertools/ledger/databases/DatabaseExtensionSpec.kt index eb654dd..ead27c0 100644 --- a/src/main/kotlin/net/quiltservertools/ledger/databases/DatabaseExtensionSpec.kt +++ b/src/main/kotlin/net/quiltservertools/ledger/databases/DatabaseExtensionSpec.kt @@ -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(), "properties") -} + val maxPoolSize by optional(10, "maxPoolSize") +} \ No newline at end of file