FEATURE: rake posts:destroy_old_user_data_exports
Historically we would keep the user data export posts around but delete the uploads. This leaves a lot of broken uploads in the system. This rake task allows us to clean up old mess.
This commit is contained in:
parent
cac7e43ba7
commit
954293655f
|
@ -106,7 +106,6 @@ module Jobs
|
||||||
def user_list_export
|
def user_list_export
|
||||||
return enum_for(:user_list_export) unless block_given?
|
return enum_for(:user_list_export) unless block_given?
|
||||||
|
|
||||||
user_array = []
|
|
||||||
user_field_ids = UserField.pluck(:id)
|
user_field_ids = UserField.pluck(:id)
|
||||||
|
|
||||||
condition = {}
|
condition = {}
|
||||||
|
|
|
@ -493,3 +493,35 @@ task 'posts:missing_uploads', [:single_site] => :environment do |_, args|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_old_user_data_exports
|
||||||
|
topics = Topic.with_deleted.where(<<~SQL, 2.days.ago)
|
||||||
|
slug = 'user-archive-data-export-complete' AND
|
||||||
|
archetype = 'private_message' AND
|
||||||
|
posts_count = 1 AND
|
||||||
|
created_at < ? AND
|
||||||
|
user_id = -1
|
||||||
|
SQL
|
||||||
|
|
||||||
|
puts "Found #{topics.count} old user data exports on #{RailsMultisite::ConnectionManagement.current_db}, destroying"
|
||||||
|
puts
|
||||||
|
topics.each do |t|
|
||||||
|
Topic.transaction do
|
||||||
|
t.posts.first.destroy!
|
||||||
|
t.destroy!
|
||||||
|
print "."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "done"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'destroys all user archive PMs (they may contain broken images)'
|
||||||
|
task 'posts:destroy_old_user_data_exports' => :environment do
|
||||||
|
if RailsMultisite::ConnectionManagement.current_db != "default"
|
||||||
|
destroy_old_user_data_exports
|
||||||
|
else
|
||||||
|
RailsMultisite::ConnectionManagement.each_connection do
|
||||||
|
destroy_old_user_data_exports
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue