mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #10840 from creative-commoners/pulls/5/eager-optimise
ENH Cache $item->ID for eager loading
This commit is contained in:
commit
87d82ee0ce
@ -928,6 +928,8 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
|||||||
|
|
||||||
private function setDataObjectEagerLoadedData(DataObject $item): void
|
private function setDataObjectEagerLoadedData(DataObject $item): void
|
||||||
{
|
{
|
||||||
|
// cache $item->ID at the top of this method to reduce calls to ViewableData::__get()
|
||||||
|
$itemID = $item->ID;
|
||||||
foreach (array_keys($this->eagerLoadedData) as $eagerLoadRelation) {
|
foreach (array_keys($this->eagerLoadedData) as $eagerLoadRelation) {
|
||||||
list($dataClasses, $relations) = $this->getEagerLoadVariables($eagerLoadRelation);
|
list($dataClasses, $relations) = $this->getEagerLoadVariables($eagerLoadRelation);
|
||||||
$dataClass = $dataClasses[count($dataClasses) - 2];
|
$dataClass = $dataClasses[count($dataClasses) - 2];
|
||||||
@ -935,7 +937,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
|||||||
foreach (array_keys($this->eagerLoadedData[$eagerLoadRelation]) as $eagerLoadID) {
|
foreach (array_keys($this->eagerLoadedData[$eagerLoadRelation]) as $eagerLoadID) {
|
||||||
$eagerLoadedData = $this->eagerLoadedData[$eagerLoadRelation][$eagerLoadID][$relation];
|
$eagerLoadedData = $this->eagerLoadedData[$eagerLoadRelation][$eagerLoadID][$relation];
|
||||||
if ($dataClass === $dataClasses[0]) {
|
if ($dataClass === $dataClasses[0]) {
|
||||||
if ($eagerLoadID === $item->ID) {
|
if ($eagerLoadID === $itemID) {
|
||||||
$item->setEagerLoadedData($relation, $eagerLoadedData);
|
$item->setEagerLoadedData($relation, $eagerLoadedData);
|
||||||
}
|
}
|
||||||
} elseif ($dataClass === $dataClasses[1]) {
|
} elseif ($dataClass === $dataClasses[1]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user