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

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 9875af739f
commit b75a4151c8
2 changed files with 63 additions and 33 deletions

View file

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

View file

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