1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 14:51:06 +01:00

Optimize loading draft revisions

Summary:
This is killing us since D3615.

Maybe we should also change `differential_inlinecomment` index <commentID> to <commentID, authorPHID>.

Test Plan: Checked queries at **/differential/** with comment drafts.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3667
This commit is contained in:
vrana 2012-10-09 11:49:48 -07:00
parent ce1a585166
commit 07db53b6f8

View file

@ -485,17 +485,29 @@ final class DifferentialRevisionQuery {
$conn_r = $table->establishConnection('r');
if ($this->draftAuthors) {
$this->draftRevisions = array();
$draft_key = 'differential-comment-';
$drafts = id(new PhabricatorDraft())->loadAllWhere(
'authorPHID IN (%Ls) AND draftKey LIKE %> AND draft != %s',
$this->draftAuthors,
$draft_key,
'');
$this->draftRevisions = array();
$len = strlen($draft_key);
foreach ($drafts as $draft) {
$this->draftRevisions[] = substr($draft->getDraftKey(), $len);
}
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
'commentID IS NULL AND authorPHID IN (%Ls)',
$this->draftAuthors);
foreach ($inlines as $inline) {
$this->draftRevisions[] = $inline->getRevisionID();
}
if (!$this->draftRevisions) {
return array();
}
}
$select = qsprintf(
@ -599,16 +611,6 @@ final class DifferentialRevisionQuery {
$this->responsibles);
}
if ($this->draftAuthors) {
$joins[] = qsprintf(
$conn_r,
'LEFT JOIN %T inline_comment ON inline_comment.revisionID = r.id '.
'AND inline_comment.commentID IS NULL '.
'AND inline_comment.authorPHID IN (%Ls)',
id(new DifferentialInlineComment())->getTableName(),
$this->draftAuthors);
}
$joins = implode(' ', $joins);
return $joins;
@ -642,17 +644,13 @@ final class DifferentialRevisionQuery {
$this->authors);
}
if ($this->draftAuthors) {
$condition = 'inline_comment.id IS NOT NULL';
if ($this->draftRevisions) {
$condition = qsprintf(
$conn_r,
'(%Q OR r.id IN (%Ld))',
$condition,
$this->draftRevisions);
}
$where[] = $condition;
if ($this->draftRevisions) {
$where[] = qsprintf(
$conn_r,
'r.id IN (%Ld)',
$this->draftRevisions);
}
if ($this->revIDs) {
$where[] = qsprintf(
$conn_r,