v0.48.1 Further attempts to address MariaDB challenges and make things as foolproof as possible.

This commit is contained in:
David Sainty 2024-08-18 19:36:56 +10:00
parent 395b2e9c49
commit 87f2733dbd

View File

@ -1,8 +1,9 @@
# Federated Computer, Inc. # Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D. # David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- CleanUp Script # 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__) require File.expand_path("../../../../config/environment", __FILE__)
class GossamerForumsCleaner class GossamerForumsCleaner
@ -58,6 +59,30 @@ class GossamerForumsCleaner
end end
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 def cleanup_messages
puts "Cleaning up imported personal messages..." puts "Cleaning up imported personal messages..."
# Find all personal messages (inbox) that were imported and delete them # Find all personal messages (inbox) that were imported and delete them
@ -78,7 +103,7 @@ class GossamerForumsCleaner
puts "Cleanup beginning!" puts "Cleanup beginning!"
# cleanup_messages # cleanup_messages
cleanup_topics cleanup_topics
cleanup_posts cleanup_posts_parallel
# cleanup_categories # cleanup_categories
# cleanup_users # cleanup_users
puts "Cleanup complete!" puts "Cleanup complete!"