1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-17 01:08:41 +01:00

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -45,7 +45,7 @@ abstract class PhabricatorApplicationTransactionQuery
return $this;
}
public function loadPage() {
protected function loadPage() {
$table = $this->getTemplateApplicationTransaction();
$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;
}
$page = $this->loadPage();
try {
$page = $this->loadPage();
} catch (PhabricatorEmptyQueryException $ex) {
$page = array();
}
$visible = $this->willFilterPage($page);
$visible = $filter->apply($visible);