From 0f958f94cb17c7e6e6564ebc7241f3ab9bf091f7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 May 2024 19:36:09 +0600 Subject: [PATCH] fix in plugin of ratings gc --- CHANGELOG.md | 4 ++++ ratings/gc/src/jvmMain/kotlin/Plugin.kt | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 463a981..1a46206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.5.6 +* `Ratings`: + * `GC`: + * Now GC will autoclear ratings even if post is absent in posts repo + ## 0.5.5 * Dependencies update diff --git a/ratings/gc/src/jvmMain/kotlin/Plugin.kt b/ratings/gc/src/jvmMain/kotlin/Plugin.kt index f3d377c..4cb3957 100644 --- a/ratings/gc/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/gc/src/jvmMain/kotlin/Plugin.kt @@ -62,7 +62,9 @@ object Plugin : Plugin { suspend fun doAutoClear() { val dropCreatedBefore = DateTime.now() - (autoclear.skipPostAge ?: 0).seconds ratingsRepo.getPostsWithRatingLessEq(autoclear.rating).keys.forEach { - if ((postsRepo.getPostCreationTime(it) ?: return@forEach) < dropCreatedBefore) { + val postCreationDateTime = postsRepo.getPostCreationTime(it) ?: (dropCreatedBefore - 1.seconds) // do dropping if post creation time is not available + if (postCreationDateTime < dropCreatedBefore) { + ratingsRepo.unset(it) postsRepo.deleteById(it) } }