Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ makeevrserg.java.ktarget=21
# Project
makeevrserg.project.name=AstraRating
makeevrserg.project.group=ru.astrainteractive.astrarating
makeevrserg.project.version.string=1.21.0
makeevrserg.project.version.string=1.21.1
makeevrserg.project.description=Rating plugin for EmpireProjekt
makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
makeevrserg.project.url=https://empireprojekt.ru
Expand Down
2 changes: 1 addition & 1 deletion instances/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ minecraftProcessResource {

astraShadowJar {
requireShadowJarTask {
destination = File("/home/makeevrserg/Desktop/server/data/plugins")
destination = File("/home/makeevrserg/Desktop/temp-server/build/bukkit/plugins")
.takeIf { it.exists() }
?: File(rootDir, "jars")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JCache<K : Any, V : Any>(
private val updateAfterAccess: Duration,
maximumSize: Long,
private val coroutineScope: CoroutineScope,
private val update: suspend CoroutineScope.(K) -> V
private val update: suspend CoroutineScope.(K) -> V?
) {
private val limitedDispatcher = Dispatchers.IO.limitedParallelism(1)
private val cache: Cache<K, Data<V>> = Cache.Builder<K, Data<V>>()
Expand All @@ -32,16 +32,20 @@ class JCache<K : Any, V : Any>(

private suspend fun refreshAndGet(key: K) = withContext(limitedDispatcher) {
val updated = update.invoke(this, key)
val data = Data(updated)
cache.put(key, data)
data.data
if (updated != null) {
val data = Data(updated)
cache.put(key, data)
data.data
} else {
null
}
}

private fun refresh(key: K) = coroutineScope.launch(limitedDispatcher) {
refreshAndGet(key)
}

suspend fun get(key: K): V {
suspend fun get(key: K): V? {
return getIfPresent(key) ?: refreshAndGet(key)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class AllRatingsCachedRepositoryImpl(

override suspend fun fetchUsersTotalRating(): List<RatedUserDTO> {
return withContext(dispatchers.IO) {
jcache.get(Unit)
jcache.get(Unit).orEmpty()
}
}

Expand Down
Loading