mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 05:09:06 +02:00
Merge pull request #8495 from micmania1/bugfix/828-grapql-asset-admin-memory
BUGFIX #828 optimised query in graphql asset admin
This commit is contained in:
commit
f4085300ce
@ -354,10 +354,11 @@ class InheritedPermissions implements PermissionChecker, MemberCacheFlusher
|
|||||||
|
|
||||||
// Get the uninherited permissions
|
// Get the uninherited permissions
|
||||||
$typeField = $this->getPermissionField($type);
|
$typeField = $this->getPermissionField($type);
|
||||||
|
$baseTable = DataObject::getSchema()->baseDataTable($this->getBaseClass());
|
||||||
|
|
||||||
if ($member && $member->ID) {
|
if ($member && $member->ID) {
|
||||||
// Determine if this member matches any of the group or other rules
|
// Determine if this member matches any of the group or other rules
|
||||||
$groupJoinTable = $this->getJoinTable($type);
|
$groupJoinTable = $this->getJoinTable($type);
|
||||||
$baseTable = DataObject::getSchema()->baseDataTable($this->getBaseClass());
|
|
||||||
$uninheritedPermissions = $stageRecords
|
$uninheritedPermissions = $stageRecords
|
||||||
->where([
|
->where([
|
||||||
"(\"$typeField\" IN (?, ?) OR " . "(\"$typeField\" = ? AND \"$groupJoinTable\".\"{$baseTable}ID\" IS NOT NULL))"
|
"(\"$typeField\" IN (?, ?) OR " . "(\"$typeField\" = ? AND \"$groupJoinTable\".\"{$baseTable}ID\" IS NOT NULL))"
|
||||||
@ -383,25 +384,35 @@ class InheritedPermissions implements PermissionChecker, MemberCacheFlusher
|
|||||||
$result = array_fill_keys($uninheritedPermissions, true) + $result;
|
$result = array_fill_keys($uninheritedPermissions, true) + $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group $potentiallyInherited by ParentID; we'll look at the permission of all those parents and
|
// This looks for any of our subjects who has their permission set to "inherited" in the CMS.
|
||||||
// then see which ones the user has permission on
|
// We group these and run a batch permission check on all parents. This gives us the result
|
||||||
|
// of whether the user has permission to edit this object.
|
||||||
$groupedByParent = [];
|
$groupedByParent = [];
|
||||||
$potentiallyInherited = $stageRecords->filter($typeField, self::INHERIT);
|
$potentiallyInherited = $stageRecords->filter($typeField, self::INHERIT)
|
||||||
|
->sort("\"{$baseTable}\".\"ID\"")
|
||||||
|
->dataQuery()
|
||||||
|
->query()
|
||||||
|
->setSelect([
|
||||||
|
"\"{$baseTable}\".\"ID\"",
|
||||||
|
"\"{$baseTable}\".\"ParentID\""
|
||||||
|
])
|
||||||
|
->execute();
|
||||||
|
|
||||||
foreach ($potentiallyInherited as $item) {
|
foreach ($potentiallyInherited as $item) {
|
||||||
/** @var DataObject|Hierarchy $item */
|
/** @var DataObject|Hierarchy $item */
|
||||||
if ($item->ParentID) {
|
if ($item['ParentID']) {
|
||||||
if (!isset($groupedByParent[$item->ParentID])) {
|
if (!isset($groupedByParent[$item['ParentID']])) {
|
||||||
$groupedByParent[$item->ParentID] = [];
|
$groupedByParent[$item['ParentID']] = [];
|
||||||
}
|
}
|
||||||
$groupedByParent[$item->ParentID][] = $item->ID;
|
$groupedByParent[$item['ParentID']][] = $item['ID'];
|
||||||
} else {
|
} else {
|
||||||
// Fail over to default permission check for Inherit and ParentID = 0
|
// Fail over to default permission check for Inherit and ParentID = 0
|
||||||
$result[$item->ID] = $this->checkDefaultPermissions($type, $member);
|
$result[$item['ID']] = $this->checkDefaultPermissions($type, $member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy permissions from parent to child
|
// Copy permissions from parent to child
|
||||||
if ($groupedByParent) {
|
if (!empty($groupedByParent)) {
|
||||||
$actuallyInherited = $this->batchPermissionCheck(
|
$actuallyInherited = $this->batchPermissionCheck(
|
||||||
$type,
|
$type,
|
||||||
array_keys($groupedByParent),
|
array_keys($groupedByParent),
|
||||||
|
Loading…
Reference in New Issue
Block a user