Differential D16906 Diff 40708 src/infrastructure/daemon/workers/query/PhabricatorWorkerTaskQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/query/PhabricatorWorkerTaskQuery.php
- This file was copied from src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php.
<?php | <?php | ||||
final class PhabricatorWorkerArchiveTaskQuery | abstract class PhabricatorWorkerTaskQuery | ||||
extends PhabricatorQuery { | extends PhabricatorQuery { | ||||
private $ids; | private $ids; | ||||
private $dateModifiedSince; | private $dateModifiedSince; | ||||
private $dateCreatedBefore; | private $dateCreatedBefore; | ||||
private $objectPHIDs; | private $objectPHIDs; | ||||
private $classNames; | private $classNames; | ||||
private $limit; | private $limit; | ||||
private $minFailureCount; | |||||
private $maxFailureCount; | |||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withDateModifiedSince($timestamp) { | public function withDateModifiedSince($timestamp) { | ||||
$this->dateModifiedSince = $timestamp; | $this->dateModifiedSince = $timestamp; | ||||
Show All 10 Lines | public function withObjectPHIDs(array $phids) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withClassNames(array $names) { | public function withClassNames(array $names) { | ||||
$this->classNames = $names; | $this->classNames = $names; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setLimit($limit) { | public function withFailureCountBetween($min, $max) { | ||||
$this->limit = $limit; | $this->minFailureCount = $min; | ||||
$this->maxFailureCount = $max; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function execute() { | public function setLimit($limit) { | ||||
$task_table = new PhabricatorWorkerArchiveTask(); | $this->limit = $limit; | ||||
return $this; | |||||
$conn_r = $task_table->establishConnection('r'); | |||||
$rows = queryfx_all( | |||||
$conn_r, | |||||
'SELECT * FROM %T %Q %Q %Q', | |||||
$task_table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $task_table->loadAllFromArray($rows); | |||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
$where = array(); | $where = array(); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
Show All 24 Lines | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
if ($this->classNames !== null) { | if ($this->classNames !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'taskClass IN (%Ls)', | 'taskClass IN (%Ls)', | ||||
$this->classNames); | $this->classNames); | ||||
} | } | ||||
if ($this->minFailureCount !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'failureCount >= %d', | |||||
$this->minFailureCount); | |||||
} | |||||
if ($this->maxFailureCount !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'failureCount <= %d', | |||||
epriestley: Maybe `<=` for consistency with `$min` and MySQL's `BETWEEN`? | |||||
$this->maxFailureCount); | |||||
} | |||||
return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
} | } | ||||
private function buildOrderClause(AphrontDatabaseConnection $conn_r) { | protected function buildOrderClause(AphrontDatabaseConnection $conn_r) { | ||||
// NOTE: The garbage collector executes this query with a date constraint, | // NOTE: The garbage collector executes this query with a date constraint, | ||||
// and the query is inefficient if we don't use the same key for ordering. | // and the query is inefficient if we don't use the same key for ordering. | ||||
// See T9808 for discussion. | // See T9808 for discussion. | ||||
if ($this->dateCreatedBefore) { | if ($this->dateCreatedBefore) { | ||||
return qsprintf($conn_r, 'ORDER BY dateCreated DESC, id DESC'); | return qsprintf($conn_r, 'ORDER BY dateCreated DESC, id DESC'); | ||||
} else if ($this->dateModifiedSince) { | } else if ($this->dateModifiedSince) { | ||||
return qsprintf($conn_r, 'ORDER BY dateModified DESC, id DESC'); | return qsprintf($conn_r, 'ORDER BY dateModified DESC, id DESC'); | ||||
} else { | } else { | ||||
return qsprintf($conn_r, 'ORDER BY id DESC'); | return qsprintf($conn_r, 'ORDER BY id DESC'); | ||||
} | } | ||||
} | } | ||||
private function buildLimitClause(AphrontDatabaseConnection $conn_r) { | protected function buildLimitClause(AphrontDatabaseConnection $conn_r) { | ||||
$clause = ''; | $clause = ''; | ||||
if ($this->limit) { | if ($this->limit) { | ||||
$clause = qsprintf($conn_r, 'LIMIT %d', $this->limit); | $clause = qsprintf($conn_r, 'LIMIT %d', $this->limit); | ||||
} | } | ||||
return $clause; | return $clause; | ||||
} | } | ||||
} | } |
Maybe <= for consistency with $min and MySQL's BETWEEN?