Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/fact/extract/PhabricatorFactUpdateIterator.php b/src/applications/fact/extract/PhabricatorFactUpdateIterator.php
index c0d229084f..910c3ffc7a 100644
--- a/src/applications/fact/extract/PhabricatorFactUpdateIterator.php
+++ b/src/applications/fact/extract/PhabricatorFactUpdateIterator.php
@@ -1,91 +1,92 @@
<?php
/**
* 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
* dateModified column.
*/
final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator {
private $cursor;
private $object;
private $position;
private $ignoreUpdatesDuration = 15;
public function __construct(LiskDAO $object) {
$this->object = $object;
}
public function setPosition($position) {
$this->position = $position;
return $this;
}
protected function didRewind() {
$this->cursor = $this->position;
}
protected function getCursorFromObject($object) {
if ($object->hasProperty('dateModified')) {
return $object->getDateModified().':'.$object->getID();
} else {
return $object->getID();
}
}
+ #[\ReturnTypeWillChange]
public function key() {
return $this->getCursorFromObject($this->current());
}
protected function loadPage() {
if ($this->object->hasProperty('dateModified')) {
if ($this->cursor) {
list($after_epoch, $after_id) = explode(':', $this->cursor);
} else {
$after_epoch = 0;
$after_id = 0;
}
// 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
// was updated on the current second, another update later on in this
// second could affect an object with a lower ID, and we'd skip that
// update. To avoid this, just ignore any rows which have been updated in
// the last few seconds. This also reduces the amount of work we need to
// do if an object is repeatedly updated; we will just look at the end
// state without processing the intermediate states. Finally, this gives
// us reasonable protections against clock skew between the machine the
// daemon is running on and any machines performing writes.
$page = $this->object->loadAllWhere(
'((dateModified > %d) OR (dateModified = %d AND id > %d))
AND (dateModified < %d - %d)
ORDER BY dateModified ASC, id ASC LIMIT %d',
$after_epoch,
$after_epoch,
$after_id,
time(),
$this->ignoreUpdatesDuration,
$this->getPageSize());
} else {
if ($this->cursor) {
$after_id = $this->cursor;
} else {
$after_id = 0;
}
$page = $this->object->loadAllWhere(
'id > %d ORDER BY id ASC LIMIT %d',
$after_id,
$this->getPageSize());
}
if ($page) {
$this->cursor = $this->getCursorFromObject(end($page));
}
return $page;
}
}
diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php b/src/applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php
index 514ad7013c..b477dd7e31 100644
--- a/src/applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php
+++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php
@@ -1,59 +1,60 @@
<?php
final class HarbormasterBuildLogChunkIterator
extends PhutilBufferedIterator {
private $log;
private $cursor;
private $asString;
private $min = 0;
private $max = PHP_INT_MAX;
public function __construct(HarbormasterBuildLog $log) {
$this->log = $log;
}
protected function didRewind() {
$this->cursor = $this->min;
}
+ #[\ReturnTypeWillChange]
public function key() {
return $this->current()->getID();
}
public function setRange($min, $max) {
$this->min = (int)$min;
$this->max = (int)$max;
return $this;
}
public function setAsString($as_string) {
$this->asString = $as_string;
return $this;
}
protected function loadPage() {
if ($this->cursor > $this->max) {
return array();
}
$results = id(new HarbormasterBuildLogChunk())->loadAllWhere(
'logID = %d AND id >= %d AND id <= %d ORDER BY id ASC LIMIT %d',
$this->log->getID(),
$this->cursor,
$this->max,
$this->getPageSize());
if ($results) {
$this->cursor = last($results)->getID() + 1;
}
if ($this->asString) {
return mpull($results, 'getChunkDisplayText');
} else {
return $results;
}
}
}
diff --git a/src/infrastructure/storage/lisk/LiskMigrationIterator.php b/src/infrastructure/storage/lisk/LiskMigrationIterator.php
index edd31c8123..2d2f8c98e9 100644
--- a/src/infrastructure/storage/lisk/LiskMigrationIterator.php
+++ b/src/infrastructure/storage/lisk/LiskMigrationIterator.php
@@ -1,46 +1,47 @@
<?php
/**
* Iterate over every object of a given type, without holding all of them in
* memory. This is useful for performing database migrations.
*
* $things = new LiskMigrationIterator(new LiskThing());
* foreach ($things as $thing) {
* // do something
* }
*
* NOTE: This only works on objects with a normal `id` column.
*
* @task storage
*/
final class LiskMigrationIterator extends PhutilBufferedIterator {
private $object;
private $cursor;
public function __construct(LiskDAO $object) {
$this->object = $object;
}
protected function didRewind() {
$this->cursor = 0;
}
+ #[\ReturnTypeWillChange]
public function key() {
return $this->current()->getID();
}
protected function loadPage() {
$results = $this->object->loadAllWhere(
'id > %d ORDER BY id ASC LIMIT %d',
$this->cursor,
$this->getPageSize());
if ($results) {
$this->cursor = last($results)->getID();
}
return $results;
}
}
diff --git a/src/infrastructure/storage/lisk/LiskRawMigrationIterator.php b/src/infrastructure/storage/lisk/LiskRawMigrationIterator.php
index a7edbd7f91..3d8954a269 100644
--- a/src/infrastructure/storage/lisk/LiskRawMigrationIterator.php
+++ b/src/infrastructure/storage/lisk/LiskRawMigrationIterator.php
@@ -1,39 +1,40 @@
<?php
final class LiskRawMigrationIterator extends PhutilBufferedIterator {
private $conn;
private $table;
private $cursor;
private $column = 'id';
public function __construct(AphrontDatabaseConnection $conn, $table) {
$this->conn = $conn;
$this->table = $table;
}
protected function didRewind() {
$this->cursor = 0;
}
+ #[\ReturnTypeWillChange]
public function key() {
return idx($this->current(), $this->column);
}
protected function loadPage() {
$page = queryfx_all(
$this->conn,
'SELECT * FROM %T WHERE %C > %d ORDER BY ID ASC LIMIT %d',
$this->table,
$this->column,
$this->cursor,
$this->getPageSize());
if ($page) {
$this->cursor = idx(last($page), $this->column);
}
return $page;
}
}
diff --git a/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php b/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php
index cc88678cdf..70e55509b9 100644
--- a/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php
+++ b/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php
@@ -1,48 +1,49 @@
<?php
final class PhabricatorQueryIterator extends PhutilBufferedIterator {
private $query;
private $pager;
public function __construct(PhabricatorCursorPagedPolicyAwareQuery $query) {
$this->query = $query;
}
protected function didRewind() {
$pager = new AphrontCursorPagerView();
$page_size = $this->getPageSize();
$pager->setPageSize($page_size);
$this->pager = $pager;
}
+ #[\ReturnTypeWillChange]
public function key() {
return $this->current()->getID();
}
protected function loadPage() {
if (!$this->pager) {
return array();
}
$pager = clone $this->pager;
$query = clone $this->query;
$query->setDisableOverheating(true);
$results = $query->executeWithCursorPager($pager);
// If we got less than a full page of results, this was the last set of
// results. Throw away the pager so we end iteration.
if (!$pager->getHasMoreResults()) {
$this->pager = null;
} else {
$this->pager->setAfterID($pager->getNextPageID());
}
return $results;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 12:45 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1113
Default Alt Text
(8 KB)

Event Timeline