diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php index 6b43883c78..286158c4fb 100644 --- a/src/applications/search/controller/PhabricatorApplicationSearchController.php +++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php @@ -249,6 +249,8 @@ final class PhabricatorApplicationSearchController $pager = $engine->newPagerForSavedQuery($saved_query); $pager->readFromRequest($request); + $query->setReturnPartialResultsOnOverheat(true); + $objects = $engine->executeQuery($query, $pager); $force_nux = $request->getBool('nux'); @@ -798,6 +800,7 @@ final class PhabricatorApplicationSearchController $object = $query ->setViewer(PhabricatorUser::getOmnipotentUser()) ->setLimit(1) + ->setReturnPartialResultsOnOverheat(true) ->execute(); if ($object) { return null; diff --git a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php index 5561f374fb..8780584f94 100644 --- a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php @@ -45,6 +45,8 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { */ private $raisePolicyExceptions; private $isOverheated; + private $returnPartialResultsOnOverheat; + private $disableOverheating; /* -( Query Configuration )------------------------------------------------ */ @@ -130,6 +132,16 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { return $this; } + final public function setReturnPartialResultsOnOverheat($bool) { + $this->returnPartialResultsOnOverheat = $bool; + return $this; + } + + final public function setDisableOverheating($disable_overheating) { + $this->disableOverheating = $disable_overheating; + return $this; + } + /* -( Query Execution )---------------------------------------------------- */ @@ -319,9 +331,22 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { break; } - if ($overheat_limit && ($total_seen >= $overheat_limit)) { - $this->isOverheated = true; - break; + if (!$this->disableOverheating) { + if ($overheat_limit && ($total_seen >= $overheat_limit)) { + $this->isOverheated = true; + + if (!$this->returnPartialResultsOnOverheat) { + throw new Exception( + pht( + 'Query (of class "%s") overheated: examined more than %s '. + 'raw rows without finding %s visible objects.', + get_class($this), + new PhutilNumber($overheat_limit), + new PhutilNumber($need))); + } + + break; + } } } while (true); diff --git a/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php b/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php index 03aaf5707e..648b83863a 100644 --- a/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php +++ b/src/infrastructure/storage/lisk/PhabricatorQueryIterator.php @@ -25,6 +25,8 @@ final class PhabricatorQueryIterator extends PhutilBufferedIterator { $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