Skip to content

Commit

Permalink
Merge pull request #10840 from creative-commoners/pulls/5/eager-optimise
Browse files Browse the repository at this point in the history
ENH Cache $item->ID for eager loading
  • Loading branch information
GuySartorelli authored Jun 28, 2023
2 parents 0c40cc9 + ed07303 commit 87d82ee
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ORM/DataList.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,16 @@ public function createDataObject($row)

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) {
list($dataClasses, $relations) = $this->getEagerLoadVariables($eagerLoadRelation);
$dataClass = $dataClasses[count($dataClasses) - 2];
$relation = $relations[count($relations) - 1];
foreach (array_keys($this->eagerLoadedData[$eagerLoadRelation]) as $eagerLoadID) {
$eagerLoadedData = $this->eagerLoadedData[$eagerLoadRelation][$eagerLoadID][$relation];
if ($dataClass === $dataClasses[0]) {
if ($eagerLoadID === $item->ID) {
if ($eagerLoadID === $itemID) {
$item->setEagerLoadedData($relation, $eagerLoadedData);
}
} elseif ($dataClass === $dataClasses[1]) {
Expand Down

0 comments on commit 87d82ee

Please sign in to comment.