@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add PhabricatorQueryIterator, for buffered iteration over a CursorPagedPolicyAwareQuery

Summary:
See D19446. This should make it easier to process larger, more complex result sets in constant memory.

Today, `LiskMigrationIterator` takes constant memory but can't apply `needX()` reqeusts or `withY(...)` constraints.

Using a raw `Query` can handle this stuff, but requires memory proportional to the size of the result set.

Offer the best of both worlds: constant memory and full access to the power of `Query` classes.

Test Plan:
Used this script to iterate over every commit, saw sensible behavior:

```name=list-commits.php
<?php

require_once 'scripts/init/init-script.php';

$viewer = PhabricatorUser::getOmnipotentUser();

$query = id(new DiffusionCommitQuery())
->setViewer($viewer);

$iterator = new PhabricatorQueryIterator($query);
foreach ($iterator as $commit) {
echo $commit->getID()."\n";
}
```

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19450

+43
+2
src/__phutil_library_map__.php
··· 4032 4032 'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php', 4033 4033 'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php', 4034 4034 'PhabricatorQueryConstraint' => 'infrastructure/query/constraint/PhabricatorQueryConstraint.php', 4035 + 'PhabricatorQueryIterator' => 'infrastructure/storage/lisk/PhabricatorQueryIterator.php', 4035 4036 'PhabricatorQueryOrderItem' => 'infrastructure/query/order/PhabricatorQueryOrderItem.php', 4036 4037 'PhabricatorQueryOrderTestCase' => 'infrastructure/query/order/__tests__/PhabricatorQueryOrderTestCase.php', 4037 4038 'PhabricatorQueryOrderVector' => 'infrastructure/query/order/PhabricatorQueryOrderVector.php', ··· 9876 9877 'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck', 9877 9878 'PhabricatorQuery' => 'Phobject', 9878 9879 'PhabricatorQueryConstraint' => 'Phobject', 9880 + 'PhabricatorQueryIterator' => 'PhutilBufferedIterator', 9879 9881 'PhabricatorQueryOrderItem' => 'Phobject', 9880 9882 'PhabricatorQueryOrderTestCase' => 'PhabricatorTestCase', 9881 9883 'PhabricatorQueryOrderVector' => array(
+41
src/infrastructure/storage/lisk/PhabricatorQueryIterator.php
··· 1 + <?php 2 + 3 + final class PhabricatorQueryIterator extends PhutilBufferedIterator { 4 + 5 + private $query; 6 + private $pager; 7 + 8 + public function __construct(PhabricatorCursorPagedPolicyAwareQuery $query) { 9 + $this->query = $query; 10 + } 11 + 12 + protected function didRewind() { 13 + $this->pager = new AphrontCursorPagerView(); 14 + } 15 + 16 + public function key() { 17 + return $this->current()->getID(); 18 + } 19 + 20 + protected function loadPage() { 21 + if (!$this->pager) { 22 + return array(); 23 + } 24 + 25 + $pager = clone $this->pager; 26 + $query = clone $this->query; 27 + 28 + $results = $query->executeWithCursorPager($pager); 29 + 30 + // If we got less than a full page of results, this was the last set of 31 + // results. Throw away the pager so we end iteration. 32 + if (count($results) < $pager->getPageSize()) { 33 + $this->pager = null; 34 + } else { 35 + $this->pager->setAfterID($pager->getNextPageID()); 36 + } 37 + 38 + return $results; 39 + } 40 + 41 + }