Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php
Show All 39 Lines | abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { | ||||
* Should we continue or throw an exception when a query result is filtered | * Should we continue or throw an exception when a query result is filtered | ||||
* by policy rules? | * by policy rules? | ||||
* | * | ||||
* Values are `true` (raise exceptions), `false` (do not raise exceptions) | * Values are `true` (raise exceptions), `false` (do not raise exceptions) | ||||
* and `null` (inherit from parent query, with no exceptions by default). | * and `null` (inherit from parent query, with no exceptions by default). | ||||
*/ | */ | ||||
private $raisePolicyExceptions; | private $raisePolicyExceptions; | ||||
private $isOverheated; | private $isOverheated; | ||||
private $returnPartialResultsOnOverheat; | |||||
private $disableOverheating; | |||||
/* -( Query Configuration )------------------------------------------------ */ | /* -( Query Configuration )------------------------------------------------ */ | ||||
/** | /** | ||||
* Set the viewer who is executing the query. Results will be filtered | * Set the viewer who is executing the query. Results will be filtered | ||||
* according to the viewer's capabilities. You must set a viewer to execute | * according to the viewer's capabilities. You must set a viewer to execute | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | /* -( Query Configuration )------------------------------------------------ */ | ||||
/** | /** | ||||
* @task config | * @task config | ||||
*/ | */ | ||||
final public function requireCapabilities(array $capabilities) { | final public function requireCapabilities(array $capabilities) { | ||||
$this->capabilities = $capabilities; | $this->capabilities = $capabilities; | ||||
return $this; | 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 )---------------------------------------------------- */ | /* -( Query Execution )---------------------------------------------------- */ | ||||
/** | /** | ||||
* Execute the query, expecting a single result. This method simplifies | * Execute the query, expecting a single result. This method simplifies | ||||
* loading objects for detail pages or edit views. | * loading objects for detail pages or edit views. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | do { | ||||
if (count($page) < $this->rawResultLimit) { | if (count($page) < $this->rawResultLimit) { | ||||
// If we have a load count but the unfiltered results contained fewer | // If we have a load count but the unfiltered results contained fewer | ||||
// objects, we know this was the last page of objects; we do not need | // objects, we know this was the last page of objects; we do not need | ||||
// to load another page because we can deduce it would be empty. | // to load another page because we can deduce it would be empty. | ||||
break; | break; | ||||
} | } | ||||
if (!$this->disableOverheating) { | |||||
if ($overheat_limit && ($total_seen >= $overheat_limit)) { | if ($overheat_limit && ($total_seen >= $overheat_limit)) { | ||||
$this->isOverheated = true; | $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; | break; | ||||
} | } | ||||
} | |||||
} while (true); | } while (true); | ||||
$results = $this->didLoadResults($results); | $results = $this->didLoadResults($results); | ||||
return $results; | return $results; | ||||
} | } | ||||
private function getPolicyFilter() { | private function getPolicyFilter() { | ||||
▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines |