Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
Show First 20 Lines • Show All 447 Lines • ▼ Show 20 Lines | if ($this->needDrafts) { | ||||
$revisions); | $revisions); | ||||
} | } | ||||
return $revisions; | return $revisions; | ||||
} | } | ||||
private function loadData() { | private function loadData() { | ||||
$table = $this->newResultObject(); | $table = $this->newResultObject(); | ||||
$conn_r = $table->establishConnection('r'); | $conn = $table->establishConnection('r'); | ||||
$selects = array(); | $selects = array(); | ||||
// NOTE: If the query includes "responsiblePHIDs", we execute it as a | // NOTE: If the query includes "responsiblePHIDs", we execute it as a | ||||
// UNION of revisions they own and revisions they're reviewing. This has | // UNION of revisions they own and revisions they're reviewing. This has | ||||
// much better performance than doing it with JOIN/WHERE. | // much better performance than doing it with JOIN/WHERE. | ||||
if ($this->responsibles) { | if ($this->responsibles) { | ||||
$basic_authors = $this->authors; | $basic_authors = $this->authors; | ||||
$basic_reviewers = $this->reviewers; | $basic_reviewers = $this->reviewers; | ||||
try { | try { | ||||
// Build the query where the responsible users are authors. | // Build the query where the responsible users are authors. | ||||
$this->authors = array_merge($basic_authors, $this->responsibles); | $this->authors = array_merge($basic_authors, $this->responsibles); | ||||
$this->reviewers = $basic_reviewers; | $this->reviewers = $basic_reviewers; | ||||
$selects[] = $this->buildSelectStatement($conn_r); | $selects[] = $this->buildSelectStatement($conn); | ||||
// Build the query where the responsible users are reviewers, or | // Build the query where the responsible users are reviewers, or | ||||
// projects they are members of are reviewers. | // projects they are members of are reviewers. | ||||
$this->authors = $basic_authors; | $this->authors = $basic_authors; | ||||
$this->reviewers = array_merge($basic_reviewers, $this->responsibles); | $this->reviewers = array_merge($basic_reviewers, $this->responsibles); | ||||
$selects[] = $this->buildSelectStatement($conn_r); | $selects[] = $this->buildSelectStatement($conn); | ||||
// Put everything back like it was. | // Put everything back like it was. | ||||
$this->authors = $basic_authors; | $this->authors = $basic_authors; | ||||
$this->reviewers = $basic_reviewers; | $this->reviewers = $basic_reviewers; | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$this->authors = $basic_authors; | $this->authors = $basic_authors; | ||||
$this->reviewers = $basic_reviewers; | $this->reviewers = $basic_reviewers; | ||||
throw $ex; | throw $ex; | ||||
} | } | ||||
} else { | } else { | ||||
$selects[] = $this->buildSelectStatement($conn_r); | $selects[] = $this->buildSelectStatement($conn); | ||||
} | } | ||||
if (count($selects) > 1) { | if (count($selects) > 1) { | ||||
$unions = null; | |||||
foreach ($selects as $select) { | |||||
if (!$unions) { | |||||
$unions = $select; | |||||
continue; | |||||
} | |||||
$unions = qsprintf( | |||||
$conn, | |||||
'%Q UNION DISTINCT %Q', | |||||
$unions, | |||||
$select); | |||||
} | |||||
$query = qsprintf( | $query = qsprintf( | ||||
$conn_r, | $conn, | ||||
'%Q %Q %Q', | '%Q %Q %Q', | ||||
implode(' UNION DISTINCT ', $selects), | $unions, | ||||
$this->buildOrderClause($conn_r, true), | $this->buildOrderClause($conn, true), | ||||
$this->buildLimitClause($conn_r)); | $this->buildLimitClause($conn)); | ||||
} else { | } else { | ||||
$query = head($selects); | $query = head($selects); | ||||
} | } | ||||
return queryfx_all($conn_r, '%Q', $query); | return queryfx_all($conn, '%Q', $query); | ||||
} | } | ||||
private function buildSelectStatement(AphrontDatabaseConnection $conn_r) { | private function buildSelectStatement(AphrontDatabaseConnection $conn_r) { | ||||
$table = new DifferentialRevision(); | $table = new DifferentialRevision(); | ||||
$select = $this->buildSelectClause($conn_r); | $select = $this->buildSelectClause($conn_r); | ||||
$from = qsprintf( | $from = qsprintf( | ||||
▲ Show 20 Lines • Show All 504 Lines • Show Last 20 Lines |