]> cat aescling's git repositories - mastodon.git/commitdiff
Make the rake mastodon:users:clear task properly clear out unconfirmed users (#1777)
authorEugen <eugen@zeonfederated.com>
Sat, 15 Apr 2017 19:55:28 +0000 (21:55 +0200)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2017 19:55:28 +0000 (21:55 +0200)
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

lib/tasks/mastodon.rake

index 15b423745595626f1cc56cd9c6c4c717ef2d0be3..54980634d354af27e92959bf91c4485063a23acd 100644 (file)
@@ -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