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!"