user_delete function is very slow

by Pankaj Sachdeva   Last Updated January 10, 2018 14:07 PM

I am writing a script to delete 200+ users. To achieve this, I write a db_select query and got all the UIDs. The I wrote foreach loop to delete users using 'user_delete' function. But this is taking lot of time to delete a single user. It will be very hard to delete 200+ users.

Can someone help me to solve this program to delete bulk users programmatically?

Tags : 7 users

Answers 1

If you want to maintain data integrity, there's not much you can do to speed the process up except upgrade your server's hardware.

user_delete calls user_delete_multiple, and it has plenty to do for each record; not just deleting the user record, it deletes fields/data, invokes hooks, clears caches, etc. All of that needs to happen or you're likely to find problems further down the line.

If you're finding that the slowdown is causing the script to timeout, you can process the list with the Batch API and solve that at least.

Incidentally, if you don't care about data integrity, you can just cherry pick the lines from user_delete_multiple that you do need, and execute those directly instead.

January 10, 2018 13:55 PM

Related Questions

Create A Sort Features In Drupal

Updated April 04, 2015 15:03 PM

Generating user accounts programatically

Updated April 22, 2015 07:03 AM

Can admins create new accounts without passwords?

Updated February 21, 2016 01:03 AM