Introduce PhabricatorEmptyQueryException

Summary: It's dumb to execute a query which we know will return an empty result.

Test Plan: Looked at comment preview with "11", didn't see "1 = 0" in DarkConsole.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5177
This commit is contained in:
vrana
2013-03-01 11:28:02 -08:00
parent 1091dc7aa1
commit b3a63a62a2
21 changed files with 35 additions and 24 deletions

View File

@@ -861,6 +861,7 @@ phutil_register_library_map(array(
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php', 'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php', 'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php', 'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php',
'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php', 'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php',
'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php', 'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php',
'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php', 'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php',
@@ -2373,6 +2374,7 @@ phutil_register_library_map(array(
'PhabricatorEmailLoginController' => 'PhabricatorAuthController', 'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
'PhabricatorEmailTokenController' => 'PhabricatorAuthController', 'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController', 'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController',
'PhabricatorEmptyQueryException' => 'Exception',
'PhabricatorEnglishTranslation' => 'PhabricatorBaseEnglishTranslation', 'PhabricatorEnglishTranslation' => 'PhabricatorBaseEnglishTranslation',
'PhabricatorEnvTestCase' => 'PhabricatorTestCase', 'PhabricatorEnvTestCase' => 'PhabricatorTestCase',
'PhabricatorErrorExample' => 'PhabricatorUIExample', 'PhabricatorErrorExample' => 'PhabricatorUIExample',

View File

@@ -16,7 +16,7 @@ final class PhabricatorChatLogChannelQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorChatLogChannel(); $table = new PhabricatorChatLogChannel();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -16,7 +16,7 @@ final class PhabricatorChatLogQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorChatLogEvent(); $table = new PhabricatorChatLogEvent();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -37,7 +37,7 @@ final class ConpherenceThreadQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new ConpherenceThread(); $table = new ConpherenceThread();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');
@@ -113,7 +113,7 @@ final class ConpherenceThreadQuery
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withObjectPHIDs(array_keys($conpherences)) ->withObjectPHIDs(array_keys($conpherences))
->needHandles(true) ->needHandles(true)
->loadPage(); ->execute();
$transactions = mgroup($transactions, 'getObjectPHID'); $transactions = mgroup($transactions, 'getObjectPHID');
foreach ($conpherences as $phid => $conpherence) { foreach ($conpherences as $phid => $conpherence) {
$current_transactions = $transactions[$phid]; $current_transactions = $transactions[$phid];

View File

@@ -22,7 +22,7 @@ final class DiffusionCommitQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorRepositoryCommit(); $table = new PhabricatorRepositoryCommit();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');
@@ -130,14 +130,14 @@ final class DiffusionCommitQuery
} }
} }
if ($sql) { if (!$sql) {
$where[] = '('.implode(' OR ', $sql).')';
} else {
// If we discarded all possible identifiers (e.g., they all referenced // If we discarded all possible identifiers (e.g., they all referenced
// bogus repositories or were all too short), make sure the query finds // bogus repositories or were all too short), make sure the query finds
// nothing. // nothing.
$where[] = qsprintf($conn_r, '1 = 0'); throw new PhabricatorEmptyQueryException('No commit identifiers.');
} }
$where[] = '('.implode(' OR ', $sql).')';
} }
if ($this->phids) { if ($this->phids) {

View File

@@ -10,7 +10,7 @@ final class PhabricatorFeedQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$story_table = new PhabricatorFeedStoryData(); $story_table = new PhabricatorFeedStoryData();
$conn = $story_table->establishConnection('r'); $conn = $story_table->establishConnection('r');

View File

@@ -22,7 +22,7 @@ final class PhabricatorFileQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorFile(); $table = new PhabricatorFile();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -45,7 +45,7 @@ final class PhabricatorNotificationQuery
/* -( Query Execution )---------------------------------------------------- */ /* -( Query Execution )---------------------------------------------------- */
public function loadPage() { protected function loadPage() {
if (!$this->userPHID) { if (!$this->userPHID) {
throw new Exception("Call setUser() before executing the query"); throw new Exception("Call setUser() before executing the query");
} }

View File

@@ -41,7 +41,7 @@ final class PhabricatorPasteQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorPaste(); $table = new PhabricatorPaste();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -25,7 +25,7 @@ final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhameBlog(); $table = new PhameBlog();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -50,7 +50,7 @@ final class PholioMockQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PholioMock(); $table = new PholioMock();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -18,7 +18,7 @@ final class PhabricatorPolicyAwareTestQuery
$this->offset = 0; $this->offset = 0;
} }
public function loadPage() { protected function loadPage() {
if ($this->getRawResultLimit()) { if ($this->getRawResultLimit()) {
return array_slice( return array_slice(
$this->results, $this->results,

View File

@@ -84,7 +84,7 @@ final class PonderQuestionQuery
} }
} }
public function loadPage() { protected function loadPage() {
$question = new PonderQuestion(); $question = new PonderQuestion();
$conn_r = $question->establishConnection('r'); $conn_r = $question->establishConnection('r');

View File

@@ -53,7 +53,7 @@ final class PhabricatorProjectQuery
return true; return true;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorProject(); $table = new PhabricatorProject();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -26,7 +26,7 @@ final class PhabricatorRepositoryQuery
return true; return true;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorRepository(); $table = new PhabricatorRepository();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -22,7 +22,7 @@ final class PhabricatorTokenGivenQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = new PhabricatorTokenGiven(); $table = new PhabricatorTokenGiven();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -10,7 +10,7 @@ final class PhabricatorTokenQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$tokens = $this->getBuiltinTokens(); $tokens = $this->getBuiltinTokens();
if ($this->phids) { if ($this->phids) {

View File

@@ -24,7 +24,7 @@ final class PhabricatorApplicationTransactionCommentQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = $this->template; $table = $this->template;
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -45,7 +45,7 @@ abstract class PhabricatorApplicationTransactionQuery
return $this; return $this;
} }
public function loadPage() { protected function loadPage() {
$table = $this->getTemplateApplicationTransaction(); $table = $this->getTemplateApplicationTransaction();
$conn_r = $table->establishConnection('r'); $conn_r = $table->establishConnection('r');

View File

@@ -0,0 +1,5 @@
<?php
final class PhabricatorEmptyQueryException extends Exception {
}

View File

@@ -170,7 +170,11 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
$this->rawResultLimit = 0; $this->rawResultLimit = 0;
} }
$page = $this->loadPage(); try {
$page = $this->loadPage();
} catch (PhabricatorEmptyQueryException $ex) {
$page = array();
}
$visible = $this->willFilterPage($page); $visible = $this->willFilterPage($page);
$visible = $filter->apply($visible); $visible = $filter->apply($visible);