1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Add HikariCP connection pool

This commit is contained in:
carbotaniuman 2021-01-29 19:31:18 -06:00
parent 6446479497
commit 5abf9dcc4c
3 changed files with 15 additions and 1 deletions

View file

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
### Changed ### Changed
- [2021-01-29] Add HikariCP connection pool [@carbotaniuman].
### Deprecated ### Deprecated

View file

@ -44,6 +44,7 @@ dependencies {
testImplementation group: "org.http4k", name: "http4k-testing-kotest", version: "$http_4k_version" testImplementation group: "org.http4k", name: "http4k-testing-kotest", version: "$http_4k_version"
runtimeOnly group: "io.netty", name: "netty-tcnative-boringssl-static", version: "2.0.34.Final" runtimeOnly group: "io.netty", name: "netty-tcnative-boringssl-static", version: "2.0.34.Final"
implementation group: 'com.zaxxer', name: 'HikariCP', version: '4.0.1'
implementation group: "com.h2database", name: "h2", version: "1.4.200" implementation group: "com.h2database", name: "h2", version: "1.4.200"
implementation "org.ktorm:ktorm-core:$ktorm_version" implementation "org.ktorm:ktorm-core:$ktorm_version"
implementation "org.ktorm:ktorm-jackson:$ktorm_version" implementation "org.ktorm:ktorm-jackson:$ktorm_version"

View file

@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.KotlinModule import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import mdnet.Main.dieWithError import mdnet.Main.dieWithError
import mdnet.cache.ImageStorage import mdnet.cache.ImageStorage
import mdnet.logging.info import mdnet.logging.info
@ -51,6 +53,8 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
private val database: Database private val database: Database
private val storage: ImageStorage private val storage: ImageStorage
private val dataSource: HikariDataSource
private var settings: ClientSettings private var settings: ClientSettings
// state that must only be accessed from the thread on the executor // state that must only be accessed from the thread on the executor
@ -72,7 +76,14 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
LOGGER.info { "Client settings loaded: $settings" } LOGGER.info { "Client settings loaded: $settings" }
database = Database.connect("jdbc:h2:$databaseFile", "org.h2.Driver") val config = HikariConfig()
config.jdbcUrl = "jdbc:h2:$databaseFile"
config.addDataSourceProperty("cachePrepStmts", "true")
config.addDataSourceProperty("prepStmtCacheSize", "100")
config.addDataSourceProperty("prepStmtCacheSqlLimit", "1000")
dataSource = HikariDataSource(config)
database = Database.connect(dataSource)
storage = ImageStorage( storage = ImageStorage(
maxSize = (settings.maxCacheSizeInMebibytes * 1024 * 1024 * 0.95).toLong(), /* MiB to bytes */ maxSize = (settings.maxCacheSizeInMebibytes * 1024 * 1024 * 0.95).toLong(), /* MiB to bytes */
cacheFolder, cacheFolder,
@ -133,6 +144,7 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
} }
storage.close() storage.close()
dataSource.close()
latch.countDown() latch.countDown()
}, },
0, TimeUnit.SECONDS 0, TimeUnit.SECONDS