mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 05:57:13 +00:00
fixes in CachedRatingsRepo
This commit is contained in:
parent
e6a0d67444
commit
aa6c62d66e
@ -71,11 +71,13 @@ object Plugin : Plugin {
|
||||
autoClearLogger.i { "Start autoclear" }
|
||||
val dropCreatedBefore = DateTime.now() - (autoclear.skipPostAge ?: 0).seconds
|
||||
autoClearLogger.i { "Posts drop created before: ${dropCreatedBefore.toStringDefault()}" }
|
||||
val idsToDelete = ratingsRepo.getPostsWithRatingLessEq(autoclear.rating).keys.filter {
|
||||
val idsToDelete = ratingsRepo.getPostsWithRatingLessEq(autoclear.rating).keys.also {
|
||||
autoClearLogger.i { "Selected posts by rating: $it" }
|
||||
}.filter {
|
||||
val postCreationDateTime = postsRepo.getPostCreationTime(it) ?: (dropCreatedBefore - 1.seconds) // do dropping if post creation time is not available
|
||||
postCreationDateTime < dropCreatedBefore
|
||||
}
|
||||
autoClearLogger.i { "Posts to drop: $idsToDelete" }
|
||||
autoClearLogger.i { "Filtered posts by datetime: $idsToDelete" }
|
||||
if (idsToDelete.isNotEmpty()) {
|
||||
runCatching { ratingsRepo.unset(idsToDelete) }
|
||||
autoClearLogger.i { "Ratings dropped" }
|
||||
|
@ -1,6 +1,8 @@
|
||||
package dev.inmo.plaguposter.ratings.repo
|
||||
|
||||
import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging
|
||||
import dev.inmo.micro_utils.pagination.utils.optionallyReverse
|
||||
import dev.inmo.micro_utils.pagination.utils.paginate
|
||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.MapKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.cache.full.FullKeyValueCacheRepo
|
||||
@ -19,20 +21,16 @@ class CachedRatingsRepo(
|
||||
count: Int?,
|
||||
exclude: List<PostId>
|
||||
): Map<PostId, Rating> {
|
||||
val result = mutableMapOf<PostId, Rating>()
|
||||
|
||||
doForAllWithNextPaging {
|
||||
kvCache.keys(it).also {
|
||||
it.results.forEach {
|
||||
val rating = get(it) ?: return@forEach
|
||||
if (it !in exclude && rating in range) {
|
||||
result[it] = rating
|
||||
}
|
||||
}
|
||||
return kvCache.getAll().filter { (it, rating) ->
|
||||
it !in exclude && rating in range
|
||||
}.let {
|
||||
if (count == null) {
|
||||
it
|
||||
} else {
|
||||
val keys = it.keys.optionallyReverse(reversed).take(count)
|
||||
keys.associateWith { id -> it.getValue(id) }
|
||||
}
|
||||
}
|
||||
|
||||
return result.toMap()
|
||||
}
|
||||
|
||||
override suspend fun getPostsWithRatingGreaterEq(
|
||||
|
Loading…
Reference in New Issue
Block a user