From 87f2733dbd75d1d4b85c0847c05d27c511df8c66 Mon Sep 17 00:00:00 2001 From: saint Date: Sun, 18 Aug 2024 19:36:56 +1000 Subject: [PATCH] v0.48.1 Further attempts to address MariaDB challenges and make things as foolproof as possible. --- goss-cleanup.rb | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/goss-cleanup.rb b/goss-cleanup.rb index 072911c..69c5ddf 100644 --- a/goss-cleanup.rb +++ b/goss-cleanup.rb @@ -1,8 +1,9 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- CleanUp Script -# v0.14 Fix for Prod-Bitnami. Prep for 20240816 run. +# v0.16 Add parallel deletion of posts. +require 'concurrent-ruby' require File.expand_path("../../../../config/environment", __FILE__) class GossamerForumsCleaner @@ -58,6 +59,30 @@ class GossamerForumsCleaner end end + def cleanup_posts_parallel + puts "Cleaning up imported posts..." + + # Define the number of threads to use + num_threads = 8 + pool = Concurrent::FixedThreadPool.new(num_threads) + + PostCustomField.where(name: 'original_gossamer_id').in_batches(of: 1000) do |batch| + batch.each do |field| + pool.post do + post = Post.find_by(id: field.post_id) + if post + puts "Deleting post #{post.id} (ID: #{post.id})" + post.destroy + end + end + end + end + + # Wait for all threads to complete + pool.shutdown + pool.wait_for_termination + end + def cleanup_messages puts "Cleaning up imported personal messages..." # Find all personal messages (inbox) that were imported and delete them @@ -78,7 +103,7 @@ class GossamerForumsCleaner puts "Cleanup beginning!" # cleanup_messages cleanup_topics - cleanup_posts + cleanup_posts_parallel # cleanup_categories # cleanup_users puts "Cleanup complete!"