From 69320a3b629c900eb855c3b562d200adcc958471 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 May 2024 19:34:10 +0600 Subject: [PATCH 1/3] start 0.5.6 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be697d..463a981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # PlaguPoster +## 0.5.6 + ## 0.5.5 * Dependencies update diff --git a/gradle.properties b/gradle.properties index c56661e..1d1336f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.5.5 +version=0.5.6 From 0f958f94cb17c7e6e6564ebc7241f3ab9bf091f7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 May 2024 19:36:09 +0600 Subject: [PATCH 2/3] 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) } } From edc75a09eea807f5643828aa707e5dc401547f05 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 May 2024 19:41:17 +0600 Subject: [PATCH 3/3] add opportunity to trigger autoclean --- ratings/gc/src/jvmMain/kotlin/Plugin.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ratings/gc/src/jvmMain/kotlin/Plugin.kt b/ratings/gc/src/jvmMain/kotlin/Plugin.kt index 4cb3957..2a3500b 100644 --- a/ratings/gc/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/gc/src/jvmMain/kotlin/Plugin.kt @@ -7,13 +7,18 @@ import dev.inmo.krontab.toSchedule import dev.inmo.krontab.utils.asFlowWithDelays import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.koin.singleWithRandomQualifier import dev.inmo.micro_utils.repos.* import dev.inmo.plagubot.Plugin +import dev.inmo.plagubot.plugins.inline.queries.models.Format +import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate +import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.ratings.models.Rating import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.types.Seconds import kotlinx.serialization.Serializable import kotlinx.serialization.json.* @@ -75,6 +80,13 @@ object Plugin : Plugin { autoclear.autoClearKrontab.toSchedule().asFlowWithDelays().subscribeSafelyWithoutExceptions(scope) { doAutoClear() } + + onCommand("clean_posts_by_ratings") { + doAutoClear() + } + koin.getOrNull() ?.addTemplate( + OfferTemplate("Force autoclear", listOf(Format("/clean_posts_by_ratings"))) + ) } } }