MINOR: faster checking if record exists

Rather than using a loop through each object, we just filter for it in the SQL query.  This is likely to speed up the code and also make it more legible.
This commit is contained in:
Nicolaas / Sunny Side Up 2023-04-28 09:40:12 +12:00 committed by GitHub
parent 73ef035bd8
commit 9660652fbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -924,15 +924,8 @@ class Member extends DataObject
}
$groupCandidateObjs = ($strict) ? $this->getManyManyComponents("Groups") : $this->Groups();
if ($groupCandidateObjs) {
foreach ($groupCandidateObjs as $groupCandidateObj) {
if ($groupCandidateObj->ID == $groupCheckObj->ID) {
return true;
}
}
}
return false;
return $groupCandidateObjs->filter(['ID' => $groupCheckObj->ID])->exists();
}
/**