From 991b0ef3d3829502066928a76bf3da1fa924f305 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 May 2024 21:42:57 +0600 Subject: [PATCH] improvements in cachedratingsrepo --- mppProjectWithSerialization.gradle | 13 ++++++- .../kotlin/repo/CachedRatingsRepo.kt | 34 ++++++++++--------- runner/deploy.sh | 2 +- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index 920edea..e1b3148 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -4,7 +4,13 @@ project.group = "$group" apply from: "$publishGradlePath" kotlin { - jvm() + jvm { + compilations.main { + kotlinOptions { + jvmTarget = "17" + } + } + } js (IR) { browser() nodejs() @@ -38,3 +44,8 @@ kotlin { } } +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + diff --git a/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt b/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt index 98e484d..2417033 100644 --- a/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt +++ b/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt @@ -15,14 +15,14 @@ class CachedRatingsRepo( private val scope: CoroutineScope, private val kvCache: MapKeyValueRepo = MapKeyValueRepo() ) : RatingsRepo, KeyValueRepo by FullKeyValueCacheRepo(base, kvCache, scope) { - override suspend fun getPosts( - range: ClosedRange, + private suspend fun getPosts( reversed: Boolean, count: Int?, - exclude: List + exclude: List, + ratingFilter: (Rating) -> Boolean ): Map { return kvCache.getAll().filter { (it, rating) -> - it !in exclude && rating in range + it !in exclude && ratingFilter(rating) }.let { if (count == null) { it @@ -32,28 +32,30 @@ class CachedRatingsRepo( } } } + override suspend fun getPosts( + range: ClosedRange, + reversed: Boolean, + count: Int?, + exclude: List + ): Map = getPosts(reversed, count, exclude) { + it in range + } override suspend fun getPostsWithRatingGreaterEq( then: Rating, reversed: Boolean, count: Int?, exclude: List - ): Map = getPosts( - then .. Rating(Double.MAX_VALUE), - reversed, - count, - exclude - ) + ): Map = getPosts(reversed, count, exclude) { + it >= then + } override suspend fun getPostsWithRatingLessEq( then: Rating, reversed: Boolean, count: Int?, exclude: List - ): Map = getPosts( - Rating(Double.MIN_VALUE) .. then, - reversed, - count, - exclude - ) + ): Map = getPosts(reversed, count, exclude) { + it <= then + } } diff --git a/runner/deploy.sh b/runner/deploy.sh index 5398972..62c6833 100755 --- a/runner/deploy.sh +++ b/runner/deploy.sh @@ -15,7 +15,7 @@ function assert_success() { app=plaguposter version="`grep ../gradle.properties -e "^version=" | sed -e "s/version=\(.*\)/\1/"`" -server=insanusmokrassar +server=docker.inmo.dev assert_success ../gradlew build assert_success sudo docker build -t $app:"$version" .