a8cteam51/safety-net

Fix performace issues for over 30k users

NickGreen opened this issue · 2 comments

When Safety Net is activated on a site with a large number of users, it takes a while to run its auto-deletion, sometimes resulting in timeouts or 504s.

  • 30k users on Pressable, it finishes after about 4.5 minutes, just under what I'm assuming is the 5 minute PHP limit
  • 50k users, it 504s

You can test this by spinning up a test site on Pressable, and using wp user generate --count=10000 a few times to generate fake users with meta.

If you want to test more than once on the same site, you'll also need to delete the safety_net_data_deleted option that gets set after the deletion function completes.


This came up here: #46

I think the solution to this is going to be to remove the foreach loop here:

foreach ( $users as $user ) {
// Skip administrators.
if ( in_array( $user->ID, $admins, true ) ) {
continue;
}
// Get all of their meta and delete it.
delete_all_users_meta( $user->ID );
// Delete the user.
$wpdb->delete( $wpdb->users, array( 'ID' => $user->ID ) );
}

And replace it with 2 DB calls to delete the usermeta and users that are NOT IN an array of admin user IDs.

Fixed here: #57

Tested at 60k users in 9 seconds.