From 8255f28d87f1e6f3973c89d9754303f4acd329f1 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sun, 1 Dec 2024 19:41:15 +0300 Subject: [PATCH 1/3] when saving post drafts, do not insert nil records in Redis (tags list) --- app/controllers/posts_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index c5fa0e04f..341db5187 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -602,7 +602,9 @@ def save_draft key_name = [:body, :saved_at].include?(key) ? base_key : "#{base_key}.#{key}" if key == :tags - RequestContext.redis.sadd(key_name, params[key]) + if params[key].present? + RequestContext.redis.sadd(key_name, params[key]) + end else RequestContext.redis.set(key_name, params[key]) end From 70f7d1cb0b5f24938c120d02eceda1e22e9af3d2 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sun, 1 Dec 2024 21:05:32 +0300 Subject: [PATCH 2/3] added a script for cleaning up post drafts --- scripts/cleanup_drafts.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/cleanup_drafts.rb diff --git a/scripts/cleanup_drafts.rb b/scripts/cleanup_drafts.rb new file mode 100644 index 000000000..27ef4eb63 --- /dev/null +++ b/scripts/cleanup_drafts.rb @@ -0,0 +1,5 @@ +redis = RequestContext.redis + +redis.scan_each(:match => "saved_post.*.*.tags") do |key| + redis.srem?(key, '') +end \ No newline at end of file From d0f9d5daad247dd22892668034e53841a5b170a5 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sun, 1 Dec 2024 22:11:39 +0300 Subject: [PATCH 3/3] added cleanup_drafts as a daily job --- config/schedule.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index 03648b0ee..39d5eee0b 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -14,6 +14,10 @@ runner 'scripts/run_spam_cleanup.rb' end +every 1.day, at: '02:20' do + runner 'scripts/cleanup_drafts.rb' +end + every 6.hours do runner 'scripts/recalc_abilities.rb' end