1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-15 10:00:55 +01:00

(stable) Allow the fulltext index to select only transactions with comments

Summary:
Ref T12997. Although we can't query by transaction type (since we can't easily enumerate all possible types which may have comments -- inline types may also have comments), we //can// just check if there's a comment row or not.

This reduces the amount of garbage we need to load to rebuild indexes for unusual objects with hundreds and hundreds of mentions.

Test Plan:
  - Used batch editor to mention a task 700 times.
  - Indexed it before and after this change, saw index time drop from {nav 1600ms > 160ms}.
  - Made some new comments on it, verified that they still indexed/queried properly.
  - Browsed around, made normal transactions, made inline comments.
  - Added a unique word to an inline comment, indexed revision, searched for word, found revision.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12997

Differential Revision: https://secure.phabricator.com/D18660
This commit is contained in:
epriestley 2017-09-28 12:48:19 -07:00
parent 0d2065e76c
commit 5e276df9c0
2 changed files with 63 additions and 33 deletions

View file

@ -25,6 +25,7 @@ final class PhabricatorTransactionsFulltextEngineExtension
$xactions = $query
->setViewer($this->getViewer())
->withObjectPHIDs(array($object->getPHID()))
->withComments(true)
->needComments(true)
->execute();

View file

@ -7,6 +7,7 @@ abstract class PhabricatorApplicationTransactionQuery
private $objectPHIDs;
private $authorPHIDs;
private $transactionTypes;
private $withComments;
private $needComments = true;
private $needHandles = true;
@ -34,10 +35,6 @@ abstract class PhabricatorApplicationTransactionQuery
abstract public function getTemplateApplicationTransaction();
protected function buildMoreWhereClauses(AphrontDatabaseConnection $conn_r) {
return array();
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
@ -58,6 +55,11 @@ abstract class PhabricatorApplicationTransactionQuery
return $this;
}
public function withComments($with_comments) {
$this->withComments = $with_comments;
return $this;
}
public function needComments($need) {
$this->needComments = $need;
return $this;
@ -70,17 +72,8 @@ abstract class PhabricatorApplicationTransactionQuery
protected function loadPage() {
$table = $this->getTemplateApplicationTransaction();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T x %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
$xactions = $table->loadAllFromArray($data);
$xactions = $this->loadStandardPage($table);
foreach ($xactions as $xaction) {
$xaction->attachViewer($this->getViewer());
@ -161,50 +154,86 @@ abstract class PhabricatorApplicationTransactionQuery
return $xactions;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->phids) {
if ($this->phids !== null) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$conn,
'x.phid IN (%Ls)',
$this->phids);
}
if ($this->objectPHIDs) {
if ($this->objectPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'objectPHID IN (%Ls)',
$conn,
'x.objectPHID IN (%Ls)',
$this->objectPHIDs);
}
if ($this->authorPHIDs) {
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'authorPHID IN (%Ls)',
$conn,
'x.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->transactionTypes) {
if ($this->transactionTypes !== null) {
$where[] = qsprintf(
$conn_r,
'transactionType IN (%Ls)',
$conn,
'x.transactionType IN (%Ls)',
$this->transactionTypes);
}
foreach ($this->buildMoreWhereClauses($conn_r) as $clause) {
$where[] = $clause;
if ($this->withComments !== null) {
if (!$this->withComments) {
$where[] = qsprintf(
$conn,
'c.id IS NULL');
}
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
return $where;
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->withComments !== null) {
$xaction = $this->getTemplateApplicationTransaction();
$comment = $xaction->getApplicationTransactionCommentObject();
if ($this->withComments) {
$joins[] = qsprintf(
$conn,
'JOIN %T c ON x.phid = c.transactionPHID',
$comment->getTableName());
} else {
$joins[] = qsprintf(
$conn,
'LEFT JOIN %T c ON x.phid = c.transactionPHID',
$comment->getTableName());
}
}
return $joins;
}
protected function shouldGroupQueryResultRows() {
if ($this->withComments !== null) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
public function getQueryApplicationClass() {
// TODO: Sort this out?
return null;
}
protected function getPrimaryTableAlias() {
return 'x';
}
}