mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-22 20:51:10 +01:00
Use Lisk sets in fact update iterator
Summary: Fact engines loading dependent objects are super slow because they load them one by one. This diff put each page in a Lisk set allowing engines to use `loadRelatives()`. It also introduces `clearSet()` method which is somewhat neccessary in PHP < 5.3 or with disabled cyclic [[ http://php.net/gc | GC ]]. Test Plan: $iterator = new PhabricatorFactUpdateIterator(new DifferentialRevision()); foreach ($iterator as $revision) { $diffs = $revision->loadRelatives(new DifferentialDiff(), 'revisionID'); echo memory_get_usage() . "\n"; } Experienced not-steadily-increasing memory usage and much faster loading. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3247
This commit is contained in:
parent
74b438db13
commit
f841491524
2 changed files with 22 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue