Removing Users taking too long Cake Acl

#1

I am removing records from users table, and it is taking too long aprox 1 min to delete a record from users and other table of ACL. How to speed this process up because i have more than 1 lakh entries in table to remove
I am Using this code to remove users
$users = $this->Users->find()->where(['group_id' => 3]);
foreach($users as $key => $value){
$id = $value->id;
if($id){
$user = $this->Users->get($id);
$this->Users->delete($user);
}
}

0 Likes

#2

There is no need to fetch every user again, you already have the entity loaded:

$users = $this->Users->find()->where(['group_id' => 3]);
foreach($users as $user) {
    $this->Users->delete($user);
}

If that still takes very long, then something in your db isn’t indexed correctly. Using debugKit’s sql log along with sql explain statements should help you solve that issue.

0 Likes