Skip to content

Commit

Permalink
Caching getParentsOrdered() in private var
Browse files Browse the repository at this point in the history
  • Loading branch information
paulzi committed Jul 29, 2015
1 parent f2d9a80 commit a248c5c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion AdjacencyListBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class AdjacencyListBehavior extends Behavior
*/
protected $node;

/**
* @var ActiveRecord[]
*/
private $_parentsOrdered;

/**
* @var array
*/
Expand Down Expand Up @@ -116,6 +121,9 @@ public function getParents($depth = null)
*/
public function getParentsOrdered()
{
if ($this->_parentsOrdered !== null) {
return $this->_parentsOrdered;
}
$parents = $this->getParents()->all();
$ids = array_flip($this->getParentsIds());
$primaryKey = $this->getPrimaryKey();
Expand All @@ -128,7 +136,7 @@ public function getParentsOrdered()
return $aIdx > $bIdx ? -1 : 1;
}
});
return $parents;
return $this->_parentsOrdered = $parents;
}

/**
Expand Down

0 comments on commit a248c5c

Please sign in to comment.