about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-15 21:55:28 +0200
committerGitHub <noreply@github.com>2017-04-15 21:55:28 +0200
commitfa08b5079d7f85c098ee9c6a0dd73bde0a20989f (patch)
tree7825b754397ef5995e84e9f46326ba24a6b5a274
parent00392d3c630d7691e3ec92b52e8f91c6c2f6f10a (diff)
Make the rake mastodon:users:clear task properly clear out unconfirmed users (#1777)
Before it cleared out user records only (e-mail, password) without
freeing up the associated username (account record). Furthermore, since
these records have no dependent records (due to no user activity)
they can be deleted quickly with delete_all instead of destroy
-rw-r--r--lib/tasks/mastodon.rake9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 15b423745..54980634d 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -76,9 +76,14 @@ namespace :mastodon do
   end
 
   namespace :users do
-    desc 'clear unconfirmed users'
+    desc 'Clear out unconfirmed users'
     task clear: :environment do
-      User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).find_each(&:destroy)
+      # Users that never confirmed e-mail never signed in, means they
+      # only have a user record and an avatar record, with no files uploaded
+      User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).find_in_batches do |batch|
+        Account.where(id: batch.map(&:account_id)).delete_all
+        batch.delete_all
+      end
     end
   end