Skip to content

Commit

Permalink
Merge pull request #2749 from inserve-paul/main
Browse files Browse the repository at this point in the history
Improve performance for hydrated collections
  • Loading branch information
drbyte authored Oct 31, 2024
2 parents 0680e7c + 4772ff8 commit 7615c44
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PermissionRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private function getHydratedPermissionCollection(): Collection
$permissionInstance = new ($this->getPermissionClass())();

return Collection::make(array_map(
fn ($item) => $permissionInstance->newInstance([], true)
fn ($item) => (clone $permissionInstance)
->setRawAttributes($this->aliasedArray(array_diff_key($item, ['r' => 0])), true)
->setRelation('roles', $this->getHydratedRoleCollection($item['r'] ?? [])),
$this->permissions['permissions']
Expand All @@ -379,7 +379,7 @@ private function hydrateRolesCache(): void
$roleInstance = new ($this->getRoleClass())();

array_map(function ($item) use ($roleInstance) {
$role = $roleInstance->newInstance([], true)
$role = (clone $roleInstance)
->setRawAttributes($this->aliasedArray($item), true);
$this->cachedRoles[$role->getKey()] = $role;
}, $this->permissions['roles']);
Expand Down

0 comments on commit 7615c44

Please sign in to comment.