Optimization for SiteTree::allowedChildren()

Adds an `Object::extend('updateAllowedChildren')` whilst also
  caching the default response

Using `get_class($this)` as cache key as this is what is used
  in `Configurable::stat($name)` to retrieve the candidates
This commit is contained in:
Lee Bradley 2017-02-14 13:48:48 +00:00 committed by Damian Mooyman
parent bd86251043
commit 0570df95a8

View File

@ -2467,8 +2467,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function allowedChildren()
{
if (isset(static::$_allowedChildren[$this->ClassName])) {
return static::$_allowedChildren[$this->ClassName];
}
$allowedChildren = static::$_allowedChildren[$this->ClassName];
} else {
// Get config based on old FIRST_SET rules
$candidates = null;
$class = get_class($this);
@ -2498,9 +2498,12 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$allowedChildren[] = $subclass;
}
}
static::$_allowedChildren[get_class($this)] = $allowedChildren;
}
}
$this->extend('updateAllowedChildren', $allowedChildren);
return static::$_allowedChildren[$this->ClassName] = $allowedChildren;
return $allowedChildren;
}
/**