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:
parent
ce1a585166
commit
07db53b6f8
|
@ -485,17 +485,29 @@ final class DifferentialRevisionQuery {
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
if ($this->draftAuthors) {
|
if ($this->draftAuthors) {
|
||||||
|
$this->draftRevisions = array();
|
||||||
|
|
||||||
$draft_key = 'differential-comment-';
|
$draft_key = 'differential-comment-';
|
||||||
$drafts = id(new PhabricatorDraft())->loadAllWhere(
|
$drafts = id(new PhabricatorDraft())->loadAllWhere(
|
||||||
'authorPHID IN (%Ls) AND draftKey LIKE %> AND draft != %s',
|
'authorPHID IN (%Ls) AND draftKey LIKE %> AND draft != %s',
|
||||||
$this->draftAuthors,
|
$this->draftAuthors,
|
||||||
$draft_key,
|
$draft_key,
|
||||||
'');
|
'');
|
||||||
$this->draftRevisions = array();
|
|
||||||
$len = strlen($draft_key);
|
$len = strlen($draft_key);
|
||||||
foreach ($drafts as $draft) {
|
foreach ($drafts as $draft) {
|
||||||
$this->draftRevisions[] = substr($draft->getDraftKey(), $len);
|
$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(
|
$select = qsprintf(
|
||||||
|
@ -599,16 +611,6 @@ final class DifferentialRevisionQuery {
|
||||||
$this->responsibles);
|
$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);
|
$joins = implode(' ', $joins);
|
||||||
|
|
||||||
return $joins;
|
return $joins;
|
||||||
|
@ -642,17 +644,13 @@ final class DifferentialRevisionQuery {
|
||||||
$this->authors);
|
$this->authors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->draftAuthors) {
|
if ($this->draftRevisions) {
|
||||||
$condition = 'inline_comment.id IS NOT NULL';
|
$where[] = qsprintf(
|
||||||
if ($this->draftRevisions) {
|
$conn_r,
|
||||||
$condition = qsprintf(
|
'r.id IN (%Ld)',
|
||||||
$conn_r,
|
$this->draftRevisions);
|
||||||
'(%Q OR r.id IN (%Ld))',
|
|
||||||
$condition,
|
|
||||||
$this->draftRevisions);
|
|
||||||
}
|
|
||||||
$where[] = $condition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->revIDs) {
|
if ($this->revIDs) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
|
|
Loading…
Reference in a new issue