Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/extract/PhabricatorFactUpdateIterator.php
<?php | <?php | ||||
/** | /** | ||||
* Iterate over objects by update time in a stable way. This iterator only works | * Iterate over objects by update time in a stable way. This iterator only works | ||||
* for "normal" Lisk objects: objects with an auto-increment ID and a | * for "normal" Lisk objects: objects with an auto-increment ID and a | ||||
* dateModified column. | * dateModified column. | ||||
*/ | */ | ||||
final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator { | final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator { | ||||
private $cursor; | private $cursor; | ||||
private $object; | private $object; | ||||
private $position; | private $position; | ||||
private $ignoreUpdatesDuration = 15; | private $ignoreUpdatesDuration = 15; | ||||
private $set; | |||||
public function __construct(LiskDAO $object) { | public function __construct(LiskDAO $object) { | ||||
$this->set = new LiskDAOSet(); | $this->object = $object; | ||||
$this->object = $object->putInSet($this->set); | |||||
} | } | ||||
public function setPosition($position) { | public function setPosition($position) { | ||||
$this->position = $position; | $this->position = $position; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function didRewind() { | protected function didRewind() { | ||||
$this->cursor = $this->position; | $this->cursor = $this->position; | ||||
} | } | ||||
protected function getCursorFromObject($object) { | protected function getCursorFromObject($object) { | ||||
if ($object->hasProperty('dateModified')) { | if ($object->hasProperty('dateModified')) { | ||||
return $object->getDateModified().':'.$object->getID(); | return $object->getDateModified().':'.$object->getID(); | ||||
} else { | } else { | ||||
return $object->getID(); | return $object->getID(); | ||||
} | } | ||||
} | } | ||||
public function key() { | public function key() { | ||||
return $this->getCursorFromObject($this->current()); | return $this->getCursorFromObject($this->current()); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
$this->set->clearSet(); | |||||
if ($this->object->hasProperty('dateModified')) { | if ($this->object->hasProperty('dateModified')) { | ||||
if ($this->cursor) { | if ($this->cursor) { | ||||
list($after_epoch, $after_id) = explode(':', $this->cursor); | list($after_epoch, $after_id) = explode(':', $this->cursor); | ||||
} else { | } else { | ||||
$after_epoch = 0; | $after_epoch = 0; | ||||
$after_id = 0; | $after_id = 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |