diff --git a/src/infrastructure/storage/lisk/LiskDAO.php b/src/infrastructure/storage/lisk/LiskDAO.php index f532e39c4e..55d7dec5e9 100644 --- a/src/infrastructure/storage/lisk/LiskDAO.php +++ b/src/infrastructure/storage/lisk/LiskDAO.php @@ -873,6 +873,10 @@ abstract class LiskDAO { return $this; } + final protected function getInSet() { + return $this->inSet; + } + /* -( Examining Objects )-------------------------------------------------- */ diff --git a/src/infrastructure/storage/lisk/LiskDAOSet.php b/src/infrastructure/storage/lisk/LiskDAOSet.php index 9c03bc70fd..de3e2782c1 100644 --- a/src/infrastructure/storage/lisk/LiskDAOSet.php +++ b/src/infrastructure/storage/lisk/LiskDAOSet.php @@ -39,9 +39,13 @@ final class LiskDAOSet { private $daos = array(); private $relatives = array(); + private $edges = array(); private $subsets = array(); public function addToSet(LiskDAO $dao) { + if ($this->relatives || $this->edges) { + throw new Exception("Don't call addToSet() after loading data!"); + } $this->daos[] = $dao; $dao->putInSet($this); return $this; @@ -54,6 +58,7 @@ final class LiskDAOSet { final public function clearSet() { $this->daos = array(); $this->relatives = array(); + $this->edges = array(); foreach ($this->subsets as $set) { $set->clearSet(); } @@ -99,4 +104,26 @@ final class LiskDAOSet { return $relatives; } + public function loadRelativeEdges($type) { + $edges = &$this->edges[$type]; + + if ($edges === null) { + if (!$this->daos) { + $edges = array(); + } else { + assert_instances_of($this->daos, 'PhabricatorLiskDAO'); + $phids = mpull($this->daos, 'getPHID', 'getPHID'); + $edges = id(new PhabricatorEdgeQuery()) + ->withSourcePHIDs($phids) + ->withEdgeTypes(array($type)) + ->execute(); + foreach ($this->daos as $dao) { + $dao->attachEdges($edges[$dao->getPHID()]); + } + } + } + + return $edges; + } + } diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php index 0e877fcd3f..3136c769ba 100644 --- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php +++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php @@ -52,6 +52,18 @@ abstract class PhabricatorLiskDAO extends LiskDAO { } + /** + * @task edges + */ + public function loadRelativeEdges($type) { + if (!$this->getInSet()) { + id(new LiskDAOSet())->addToSet($this); + } + $this->getInSet()->loadRelativeEdges($type); + return $this->getEdges($type); + } + + /** * @task edges */