mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 09:20:58 +01:00
Remove obsolete code from ManiphestTaskQuery
Summary: Ref T603. Cleans up some obsolete stuff here: - We no longer ever query by min/max priority (instead, `withPriorities(...)`). - A parent class provides limit/offset. - Result count is no longer reliable with policies. We could do "about X tasks" or something, but just drop it for now. There's only one remaining callsite anyway. Test Plan: - `grep` - Viewed task list. - Viewed a project page. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7121
This commit is contained in:
parent
3a87a95e11
commit
36343600c5
2 changed files with 3 additions and 81 deletions
|
@ -36,13 +36,8 @@ final class ManiphestTaskQuery
|
||||||
const STATUS_DUPLICATE = 'status-duplicate';
|
const STATUS_DUPLICATE = 'status-duplicate';
|
||||||
|
|
||||||
private $statuses;
|
private $statuses;
|
||||||
|
|
||||||
private $priority = null;
|
|
||||||
private $priorities;
|
private $priorities;
|
||||||
|
|
||||||
private $minPriority = null;
|
|
||||||
private $maxPriority = null;
|
|
||||||
|
|
||||||
private $groupBy = 'group-none';
|
private $groupBy = 'group-none';
|
||||||
const GROUP_NONE = 'group-none';
|
const GROUP_NONE = 'group-none';
|
||||||
const GROUP_PRIORITY = 'group-priority';
|
const GROUP_PRIORITY = 'group-priority';
|
||||||
|
@ -56,14 +51,8 @@ final class ManiphestTaskQuery
|
||||||
const ORDER_MODIFIED = 'order-modified';
|
const ORDER_MODIFIED = 'order-modified';
|
||||||
const ORDER_TITLE = 'order-title';
|
const ORDER_TITLE = 'order-title';
|
||||||
|
|
||||||
private $limit = null;
|
|
||||||
const DEFAULT_PAGE_SIZE = 1000;
|
const DEFAULT_PAGE_SIZE = 1000;
|
||||||
|
|
||||||
private $offset = 0;
|
|
||||||
private $calculateRows = false;
|
|
||||||
|
|
||||||
private $rowCount = null;
|
|
||||||
|
|
||||||
public function withAuthors(array $authors) {
|
public function withAuthors(array $authors) {
|
||||||
$this->authorPHIDs = $authors;
|
$this->authorPHIDs = $authors;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -119,22 +108,11 @@ final class ManiphestTaskQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withPriority($priority) {
|
|
||||||
$this->priority = $priority;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withPriorities(array $priorities) {
|
public function withPriorities(array $priorities) {
|
||||||
$this->priorities = $priorities;
|
$this->priorities = $priorities;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withPrioritiesBetween($min, $max) {
|
|
||||||
$this->minPriority = $min;
|
|
||||||
$this->maxPriority = $max;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withSubscribers(array $subscribers) {
|
public function withSubscribers(array $subscribers) {
|
||||||
$this->subscriberPHIDs = $subscribers;
|
$this->subscriberPHIDs = $subscribers;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -155,20 +133,6 @@ final class ManiphestTaskQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCalculateRows($calculate_rows) {
|
|
||||||
$this->calculateRows = $calculate_rows;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRowCount() {
|
|
||||||
if ($this->rowCount === null) {
|
|
||||||
throw new Exception(
|
|
||||||
"You must execute a query with setCalculateRows() before you can ".
|
|
||||||
"retrieve a row count.");
|
|
||||||
}
|
|
||||||
return $this->rowCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withAnyProjects(array $projects) {
|
public function withAnyProjects(array $projects) {
|
||||||
$this->anyProjectPHIDs = $projects;
|
$this->anyProjectPHIDs = $projects;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -200,22 +164,11 @@ final class ManiphestTaskQuery
|
||||||
$task_dao = new ManiphestTask();
|
$task_dao = new ManiphestTask();
|
||||||
$conn = $task_dao->establishConnection('r');
|
$conn = $task_dao->establishConnection('r');
|
||||||
|
|
||||||
if ($this->calculateRows) {
|
|
||||||
$calc = 'SQL_CALC_FOUND_ROWS';
|
|
||||||
|
|
||||||
// Make sure we end up in the right state if we throw a
|
|
||||||
// PhabricatorEmptyQueryException.
|
|
||||||
$this->rowCount = 0;
|
|
||||||
} else {
|
|
||||||
$calc = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$where = array();
|
$where = array();
|
||||||
$where[] = $this->buildTaskIDsWhereClause($conn);
|
$where[] = $this->buildTaskIDsWhereClause($conn);
|
||||||
$where[] = $this->buildTaskPHIDsWhereClause($conn);
|
$where[] = $this->buildTaskPHIDsWhereClause($conn);
|
||||||
$where[] = $this->buildStatusWhereClause($conn);
|
$where[] = $this->buildStatusWhereClause($conn);
|
||||||
$where[] = $this->buildStatusesWhereClause($conn);
|
$where[] = $this->buildStatusesWhereClause($conn);
|
||||||
$where[] = $this->buildPriorityWhereClause($conn);
|
|
||||||
$where[] = $this->buildPrioritiesWhereClause($conn);
|
$where[] = $this->buildPrioritiesWhereClause($conn);
|
||||||
$where[] = $this->buildAuthorWhereClause($conn);
|
$where[] = $this->buildAuthorWhereClause($conn);
|
||||||
$where[] = $this->buildOwnerWhereClause($conn);
|
$where[] = $this->buildOwnerWhereClause($conn);
|
||||||
|
@ -277,8 +230,7 @@ final class ManiphestTaskQuery
|
||||||
|
|
||||||
$rows = queryfx_all(
|
$rows = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT %Q task.* %Q %Q FROM %T task %Q %Q %Q %Q %Q %Q',
|
'SELECT task.* %Q %Q FROM %T task %Q %Q %Q %Q %Q %Q',
|
||||||
$calc,
|
|
||||||
$count,
|
$count,
|
||||||
$group_column,
|
$group_column,
|
||||||
$task_dao->getTableName(),
|
$task_dao->getTableName(),
|
||||||
|
@ -289,15 +241,6 @@ final class ManiphestTaskQuery
|
||||||
$order,
|
$order,
|
||||||
$this->buildLimitClause($conn));
|
$this->buildLimitClause($conn));
|
||||||
|
|
||||||
if ($this->calculateRows) {
|
|
||||||
$count = queryfx_one(
|
|
||||||
$conn,
|
|
||||||
'SELECT FOUND_ROWS() N');
|
|
||||||
$this->rowCount = $count['N'];
|
|
||||||
} else {
|
|
||||||
$this->rowCount = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($this->groupBy) {
|
switch ($this->groupBy) {
|
||||||
case self::GROUP_PROJECT:
|
case self::GROUP_PROJECT:
|
||||||
$data = ipull($rows, null, 'id');
|
$data = ipull($rows, null, 'id');
|
||||||
|
@ -405,23 +348,6 @@ final class ManiphestTaskQuery
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildPriorityWhereClause(AphrontDatabaseConnection $conn) {
|
|
||||||
if ($this->priority !== null) {
|
|
||||||
return qsprintf(
|
|
||||||
$conn,
|
|
||||||
'priority = %d',
|
|
||||||
$this->priority);
|
|
||||||
} elseif ($this->minPriority !== null && $this->maxPriority !== null) {
|
|
||||||
return qsprintf(
|
|
||||||
$conn,
|
|
||||||
'priority >= %d AND priority <= %d',
|
|
||||||
$this->minPriority,
|
|
||||||
$this->maxPriority);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildPrioritiesWhereClause(AphrontDatabaseConnection $conn) {
|
private function buildPrioritiesWhereClause(AphrontDatabaseConnection $conn) {
|
||||||
if ($this->priorities) {
|
if ($this->priorities) {
|
||||||
return qsprintf(
|
return qsprintf(
|
||||||
|
|
|
@ -158,10 +158,8 @@ final class PhabricatorProjectProfileController
|
||||||
->withAnyProjects(array($project->getPHID()))
|
->withAnyProjects(array($project->getPHID()))
|
||||||
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
|
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
|
||||||
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
|
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
|
||||||
->setLimit(10)
|
->setLimit(10);
|
||||||
->setCalculateRows(true);
|
|
||||||
$tasks = $query->execute();
|
$tasks = $query->execute();
|
||||||
$count = $query->getRowCount();
|
|
||||||
|
|
||||||
$phids = mpull($tasks, 'getOwnerPHID');
|
$phids = mpull($tasks, 'getOwnerPHID');
|
||||||
$phids = array_merge(
|
$phids = array_merge(
|
||||||
|
@ -175,8 +173,6 @@ final class PhabricatorProjectProfileController
|
||||||
$task_list->setTasks($tasks);
|
$task_list->setTasks($tasks);
|
||||||
$task_list->setHandles($handles);
|
$task_list->setHandles($handles);
|
||||||
|
|
||||||
$open = number_format($count);
|
|
||||||
|
|
||||||
$content = hsprintf(
|
$content = hsprintf(
|
||||||
'<div class="phabricator-profile-info-group profile-wrap-responsive">
|
'<div class="phabricator-profile-info-group profile-wrap-responsive">
|
||||||
<h1 class="phabricator-profile-info-header">%s</h1>'.
|
<h1 class="phabricator-profile-info-header">%s</h1>'.
|
||||||
|
@ -184,7 +180,7 @@ final class PhabricatorProjectProfileController
|
||||||
'%s'.
|
'%s'.
|
||||||
'</div>
|
'</div>
|
||||||
</div>',
|
</div>',
|
||||||
pht('Open Tasks (%s)', $open),
|
pht('Open Tasks'),
|
||||||
$task_list);
|
$task_list);
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|
Loading…
Reference in a new issue