Changeset View
Changeset View
Standalone View
Standalone View
src/applications/badges/query/PhabricatorBadgesQuery.php
- This file was added.
<?php | |||||
final class PhabricatorBadgesQuery | |||||
extends PhabricatorCursorPagedPolicyAwareQuery { | |||||
private $ids; | |||||
private $phids; | |||||
private $qualities; | |||||
private $statuses; | |||||
public function withIDs(array $ids) { | |||||
$this->ids = $ids; | |||||
return $this; | |||||
} | |||||
public function withPHIDs(array $phids) { | |||||
$this->phids = $phids; | |||||
return $this; | |||||
} | |||||
public function withQualities(array $qualities) { | |||||
$this->qualities = $qualities; | |||||
chad: hehehe | |||||
return $this; | |||||
} | |||||
public function withStatuses(array $statuses) { | |||||
$this->statuses = $statuses; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | |||||
$table = new PhabricatorBadge(); | |||||
$conn_r = $table->establishConnection('r'); | |||||
$rows = queryfx_all( | |||||
$conn_r, | |||||
'SELECT * FROM %T %Q %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $table->loadAllFromArray($rows); | |||||
} | |||||
protected function didFilterPage(array $badges) { | |||||
return $badges; | |||||
} | |||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | |||||
$where = array(); | |||||
$where[] = $this->buildPagingClause($conn_r); | |||||
if ($this->ids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
Done Inline ActionsThis should be simplified to: return $this->loadStandardPage($this->newResultObject()); Then implement newResultObject() (as return new PhabricatorBadge();). epriestley: This should be simplified to:
return $this->loadStandardPage($this->newResultObject())… | |||||
'id IN (%Ld)', | |||||
Done Inline ActionsUnused. epriestley: Unused. | |||||
$this->ids); | |||||
} | |||||
if ($this->phids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'phid IN (%Ls)', | |||||
$this->phids); | |||||
} | |||||
if ($this->qualities !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'quality IN (%Ls)', | |||||
$this->qualities); | |||||
} | |||||
Done Inline ActionsThis is fine as written, but could possibly be simplified a bit with getDestinationPHIDs() on the EdgeQuery. epriestley: This is fine as written, but could possibly be simplified a bit with `getDestinationPHIDs()` on… | |||||
if ($this->statuses !== null) { | |||||
Done Inline ActionsThis load+attach stuff should happen in didFilterPage(), so we don't need to load data for objects we're going to throw away a second later when we do policy filtering. This should also only happen if needRecipients() is set. Otherwise, we'll load all these edges every time, which might be a huge amount of data if there are some very common badges with thousands of recipients. epriestley: This load+attach stuff should happen in `didFilterPage()`, so we don't need to load data for… | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'status IN (%Ls)', | |||||
$this->statuses); | |||||
} | |||||
return $this->formatWhereClause($where); | |||||
} | |||||
Done Inline ActionsThis can be simplified slightly by implementing buildWhereClauseParts() instead, in modern code. epriestley: This can be simplified slightly by implementing `buildWhereClauseParts()` instead, in modern… | |||||
public function getQueryApplicationClass() { | |||||
return 'PhabricatorBadgesApplication'; | |||||
} | |||||
} |
hehehe