improvements in cachedratingsrepo

This commit is contained in:
InsanusMokrassar 2024-05-13 21:42:57 +06:00
parent aa6c62d66e
commit 991b0ef3d3
3 changed files with 31 additions and 18 deletions

View File

@ -4,7 +4,13 @@ project.group = "$group"
apply from: "$publishGradlePath" apply from: "$publishGradlePath"
kotlin { kotlin {
jvm() jvm {
compilations.main {
kotlinOptions {
jvmTarget = "17"
}
}
}
js (IR) { js (IR) {
browser() browser()
nodejs() nodejs()
@ -38,3 +44,8 @@ kotlin {
} }
} }
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

View File

@ -15,14 +15,14 @@ class CachedRatingsRepo(
private val scope: CoroutineScope, private val scope: CoroutineScope,
private val kvCache: MapKeyValueRepo<PostId, Rating> = MapKeyValueRepo() private val kvCache: MapKeyValueRepo<PostId, Rating> = MapKeyValueRepo()
) : RatingsRepo, KeyValueRepo<PostId, Rating> by FullKeyValueCacheRepo(base, kvCache, scope) { ) : RatingsRepo, KeyValueRepo<PostId, Rating> by FullKeyValueCacheRepo(base, kvCache, scope) {
override suspend fun getPosts( private suspend fun getPosts(
range: ClosedRange<Rating>,
reversed: Boolean, reversed: Boolean,
count: Int?, count: Int?,
exclude: List<PostId> exclude: List<PostId>,
ratingFilter: (Rating) -> Boolean
): Map<PostId, Rating> { ): Map<PostId, Rating> {
return kvCache.getAll().filter { (it, rating) -> return kvCache.getAll().filter { (it, rating) ->
it !in exclude && rating in range it !in exclude && ratingFilter(rating)
}.let { }.let {
if (count == null) { if (count == null) {
it it
@ -32,28 +32,30 @@ class CachedRatingsRepo(
} }
} }
} }
override suspend fun getPosts(
range: ClosedRange<Rating>,
reversed: Boolean,
count: Int?,
exclude: List<PostId>
): Map<PostId, Rating> = getPosts(reversed, count, exclude) {
it in range
}
override suspend fun getPostsWithRatingGreaterEq( override suspend fun getPostsWithRatingGreaterEq(
then: Rating, then: Rating,
reversed: Boolean, reversed: Boolean,
count: Int?, count: Int?,
exclude: List<PostId> exclude: List<PostId>
): Map<PostId, Rating> = getPosts( ): Map<PostId, Rating> = getPosts(reversed, count, exclude) {
then .. Rating(Double.MAX_VALUE), it >= then
reversed, }
count,
exclude
)
override suspend fun getPostsWithRatingLessEq( override suspend fun getPostsWithRatingLessEq(
then: Rating, then: Rating,
reversed: Boolean, reversed: Boolean,
count: Int?, count: Int?,
exclude: List<PostId> exclude: List<PostId>
): Map<PostId, Rating> = getPosts( ): Map<PostId, Rating> = getPosts(reversed, count, exclude) {
Rating(Double.MIN_VALUE) .. then, it <= then
reversed, }
count,
exclude
)
} }

View File

@ -15,7 +15,7 @@ function assert_success() {
app=plaguposter app=plaguposter
version="`grep ../gradle.properties -e "^version=" | sed -e "s/version=\(.*\)/\1/"`" version="`grep ../gradle.properties -e "^version=" | sed -e "s/version=\(.*\)/\1/"`"
server=insanusmokrassar server=docker.inmo.dev
assert_success ../gradlew build assert_success ../gradlew build
assert_success sudo docker build -t $app:"$version" . assert_success sudo docker build -t $app:"$version" .