ENH avoid multiple calls to records->count() In PermissionCheckboxSetField (#10839)

these calls are not cached and lead to duplicate queries

Co-authored-by: Michal Kleiner <mk@011.nz>
This commit is contained in:
Thomas Portelange 2023-07-04 03:34:12 +02:00 committed by GitHub
parent 110c9135e0
commit 6fa71bbf51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,6 +193,7 @@ class PermissionCheckboxSetField extends FormField
$privilegedPermissions = Permission::config()->privileged_permissions;
// loop through all available categorized permissions and see if they're assigned for the given groups
$hasMultipleRecords = $this->records?->count() > 1;
foreach ($this->source as $categoryName => $permissions) {
$options .= "<li><h5>$categoryName</h5></li>";
foreach ($permissions as $code => $permission) {
@ -222,7 +223,7 @@ class PermissionCheckboxSetField extends FormField
// interface
$disabled = ' disabled="true"';
$inheritMessage = ' (' . join(', ', $inheritedCodes[$code]) . ')';
} elseif ($this->records && $this->records->Count() > 1 && isset($uninheritedCodes[$code])) {
} elseif ($hasMultipleRecords && isset($uninheritedCodes[$code])) {
// If code assignments are collected from more than one "source group",
// show its origin automatically
$inheritMessage = ' (' . join(', ', $uninheritedCodes[$code]) . ')';