diff --git a/src/applications/fact/extract/PhabricatorFactUpdateIterator.php b/src/applications/fact/extract/PhabricatorFactUpdateIterator.php index b7c59a4499..be93cf62c1 100644 --- a/src/applications/fact/extract/PhabricatorFactUpdateIterator.php +++ b/src/applications/fact/extract/PhabricatorFactUpdateIterator.php @@ -28,8 +28,11 @@ final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator { private $position; private $ignoreUpdatesDuration = 15; + private $set; + public function __construct(LiskDAO $object) { - $this->object = $object; + $this->set = new LiskDAOSet(); + $this->object = $object->putInSet($this->set); $this->position = '0:0'; } @@ -53,6 +56,8 @@ final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator { protected function loadPage() { list($after_epoch, $after_id) = explode(':', $this->cursor); + $this->set->clearSet(); + // NOTE: We ignore recent updates because once we process an update we'll // never process rows behind it again. We need to read only rows which // we're sure no new rows will be inserted behind. If we read a row that diff --git a/src/infrastructure/storage/lisk/LiskDAOSet.php b/src/infrastructure/storage/lisk/LiskDAOSet.php index 1b343b96a4..6d8ebc4483 100644 --- a/src/infrastructure/storage/lisk/LiskDAOSet.php +++ b/src/infrastructure/storage/lisk/LiskDAOSet.php @@ -39,6 +39,7 @@ final class LiskDAOSet { private $daos = array(); private $relatives = array(); + private $subsets = array(); public function addToSet(LiskDAO $dao) { $this->daos[] = $dao; @@ -46,6 +47,20 @@ final class LiskDAOSet { return $this; } + /** + * The main purpose of this method is to break cyclic dependency. + * It removes all objects from this set and all subsets created by it. + */ + final public function clearSet() { + $this->daos = array(); + $this->relatives = array(); + foreach ($this->subsets as $set) { + $set->clearSet(); + } + return $this; + } + + /** * See @{method:LiskDAO::loadRelatives}. */ @@ -70,6 +85,7 @@ final class LiskDAOSet { $relatives = array(); } else { $set = new LiskDAOSet(); + $this->subsets[] = $set; $relatives = $object->putInSet($set)->loadAllWhere( '%C IN (%Ls) %Q', $foreign_column,