mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-11-25 08:58:45 +00:00
add cacheable settings
This commit is contained in:
parent
463a590861
commit
f943daf1ab
@ -34,6 +34,7 @@ plagubot-plugin = { module = "dev.inmo:plagubot.plugin", version.ref = "plagubot
|
||||
plagubot-bot = { module = "dev.inmo:plagubot.bot", version.ref = "plagubot" }
|
||||
microutils-repos-common = { module = "dev.inmo:micro_utils.repos.common", version.ref = "microutils" }
|
||||
microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" }
|
||||
microutils-repos-cache = { module = "dev.inmo:micro_utils.repos.cache", version.ref = "microutils" }
|
||||
kslog = { module = "dev.inmo:kslog", version.ref = "kslog" }
|
||||
|
||||
# buildscript classpaths
|
||||
|
@ -15,6 +15,7 @@ kotlin {
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api libs.microutils.repos.cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package dev.inmo.plaguposter.settings.exposed
|
||||
|
||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.MapKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
|
||||
import dev.inmo.micro_utils.repos.cache.full.FullKeyValueCacheRepo
|
||||
import dev.inmo.micro_utils.repos.cache.full.cached
|
||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.mappers.withMapper
|
||||
import dev.inmo.plaguposter.settings.repo.SettingsRepo
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
@ -44,6 +49,27 @@ inline fun <reified T : Any> ExposedSettingsRepo(
|
||||
serializer
|
||||
)
|
||||
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
inline fun <reified T : Any> CachedExposedSettingsRepo(
|
||||
database: Database,
|
||||
json: Json,
|
||||
scope: CoroutineScope,
|
||||
serializer: KSerializer<T> = T::class.serializer(),
|
||||
tableName: String = "settings_${T::class.simpleName!!}"
|
||||
) = ExposedSettingsRepo<T>(
|
||||
ExposedKeyValueRepo(
|
||||
database,
|
||||
{ long("chat_id") },
|
||||
{ text("settings") },
|
||||
tableName
|
||||
).cached(
|
||||
FullKVCache(MapKeyValueRepo()),
|
||||
scope
|
||||
),
|
||||
json,
|
||||
serializer
|
||||
)
|
||||
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
inline fun <reified T : Any> SettingsRepo(
|
||||
parent: KeyValueRepo<Long, String>,
|
||||
@ -58,3 +84,16 @@ inline fun <reified T : Any> SettingsRepo(
|
||||
serializer: KSerializer<T> = T::class.serializer(),
|
||||
tableName: String = "settings_${T::class.simpleName!!}"
|
||||
) = ExposedSettingsRepo(database, json, serializer, tableName)
|
||||
|
||||
|
||||
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
inline fun <reified T : Any> CachedSettingsRepo(
|
||||
database: Database,
|
||||
json: Json,
|
||||
scope: CoroutineScope,
|
||||
serializer: KSerializer<T> = T::class.serializer(),
|
||||
tableName: String = "settings_${T::class.simpleName!!}"
|
||||
) = CachedExposedSettingsRepo(database, json, scope, serializer, tableName)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user