Skip to content

Commit

Permalink
Fix amount of requests to db when init ACL (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
maria-rollun authored Dec 21, 2021
2 parents 2a95755 + 9d4392e commit 5364449
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$dataStorePrivilege = $container->get($serviceConfig[self::KEY_DATASTORE_PRIVILEGE_SERVICE]);
$dataStoreResource = $container->get($serviceConfig[self::KEY_DATASTORE_RESOURCE_SERVICE]);

$acl = new Acl();
$this->aclAdd($dataStoreRole, $acl, "Role");
$this->aclAdd($dataStoreResource, $acl, "Resource");

$query = new Query();

$dataStoreRuleList = $dataStoreRule->query($query);
Expand All @@ -92,6 +88,10 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$dataStoreResourceList = $dataStoreResource->query($query);
$resourceList = array_combine(array_column($dataStoreResourceList, 'id'), $dataStoreResourceList);

$acl = new Acl();
$this->aclAdd($roleList, $acl, "Role");
$this->aclAdd($resourceList, $acl, "Resource");

$dataStorePrivilegeList = $dataStorePrivilege->query($query);
$privilegeList = array_combine(array_column($dataStorePrivilegeList, 'id'), $dataStorePrivilegeList);

Expand All @@ -115,17 +115,16 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
}

/**
* @param DataStoresInterface $dataStore
* @param array $data
* @param Acl $acl
* @param $addType
*/
private function aclAdd(DataStoresInterface $dataStore, Acl $acl, $addType)
private function aclAdd(array $data, Acl $acl, $addType)
{
$data = $dataStore->query(new Query());
$iterator = new AclDataStoreIterator($data);

foreach ($iterator as $record) {
$parent = isset($record['parent_id']) ? $dataStore->read($record['parent_id'])['name'] : null;
$parent = isset($record['parent_id']) ? $data[$record['parent_id']]['name'] : null;
$acl->{"add" . $addType}($record['name'], $parent);
}
}
Expand Down

0 comments on commit 5364449

Please sign in to comment.