Skip to content

Commit

Permalink
ENH avoid multiple calls to records->count() In PermissionCheckboxSet…
Browse files Browse the repository at this point in the history
…Field (#10839)

these calls are not cached and lead to duplicate queries

Co-authored-by: Michal Kleiner <mk@011.nz>
  • Loading branch information
lekoala and michalkleiner committed Jul 4, 2023
1 parent 110c913 commit 6fa71bb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Security/PermissionCheckboxSetField.php
Expand Up @@ -193,6 +193,7 @@ public function Field($properties = [])
$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) {
Expand Down Expand Up @@ -222,7 +223,7 @@ public function Field($properties = [])
// 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]) . ')';
Expand Down

0 comments on commit 6fa71bb

Please sign in to comment.