mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Abstract access to DifferentialInlineComment behind a Query
Summary: Ref T2222. See D6260. Push all this junk behind a Query so I can move the storage out from underneath it. Test Plan: Viewed home page, list view, revision. Made draft, looked at preview, submitted draft, viewed inline, replied to inline. Reviewers: btrahan Reviewed By: btrahan CC: chad, aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D6262
This commit is contained in:
parent
44302d2f07
commit
6a2ae07791
12 changed files with 165 additions and 41 deletions
|
@ -370,6 +370,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php',
|
||||
'DifferentialInlineCommentEditView' => 'applications/differential/view/DifferentialInlineCommentEditView.php',
|
||||
'DifferentialInlineCommentPreviewController' => 'applications/differential/controller/DifferentialInlineCommentPreviewController.php',
|
||||
'DifferentialInlineCommentQuery' => 'applications/differential/query/DifferentialInlineCommentQuery.php',
|
||||
'DifferentialInlineCommentView' => 'applications/differential/view/DifferentialInlineCommentView.php',
|
||||
'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/DifferentialLinesFieldSpecification.php',
|
||||
'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/DifferentialLintFieldSpecification.php',
|
||||
|
@ -2249,6 +2250,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
|
||||
'DifferentialInlineCommentEditView' => 'AphrontView',
|
||||
'DifferentialInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController',
|
||||
'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'DifferentialInlineCommentView' => 'AphrontView',
|
||||
'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
|
|
|
@ -40,9 +40,9 @@ final class ConduitAPI_differential_getrevisioncomments_Method
|
|||
|
||||
$with_inlines = $request->getValue('inlines');
|
||||
if ($with_inlines) {
|
||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'revisionID IN (%Ld)',
|
||||
$revision_ids);
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withRevisionIDs($revision_ids)
|
||||
->execute();
|
||||
$changesets = array();
|
||||
if ($inlines) {
|
||||
$changesets = id(new DifferentialChangeset())->loadAllWhere(
|
||||
|
|
|
@ -268,10 +268,9 @@ final class DifferentialChangesetViewController extends DifferentialController {
|
|||
return;
|
||||
}
|
||||
|
||||
return id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'changesetID IN (%Ld) AND (commentID IS NOT NULL OR authorPHID = %s)',
|
||||
$changeset_ids,
|
||||
$author_phid);
|
||||
return id(new DifferentialInlineCommentQuery())
|
||||
->withAuthorAndChangesetIDs($author_phid, $changeset_ids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
private function buildRawFileResponse(
|
||||
|
|
|
@ -39,10 +39,9 @@ final class DifferentialCommentSaveController extends DifferentialController {
|
|||
->setAddedCCs($ccs)
|
||||
->save();
|
||||
} catch (DifferentialActionHasNoEffectException $no_effect) {
|
||||
$has_inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
|
||||
$request->getUser()->getPHID(),
|
||||
$revision->getID());
|
||||
$has_inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($request->getUser()->getPHID(), $revision->getID())
|
||||
->execute();
|
||||
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($request->getUser());
|
||||
|
|
|
@ -29,7 +29,9 @@ final class DifferentialInlineCommentEditController
|
|||
}
|
||||
|
||||
protected function loadComment($id) {
|
||||
return id(new DifferentialInlineComment())->load($id);
|
||||
return id(new DifferentialInlineCommentQuery())
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
}
|
||||
|
||||
protected function loadCommentForEdit($id) {
|
||||
|
|
|
@ -12,10 +12,9 @@ extends PhabricatorInlineCommentPreviewController {
|
|||
protected function loadInlineComments() {
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
|
||||
$user->getPHID(),
|
||||
$this->revisionID);
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($user->getPHID(), $this->revisionID)
|
||||
->execute();
|
||||
|
||||
return $inlines;
|
||||
}
|
||||
|
|
|
@ -194,12 +194,9 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
pht('Show All Files Inline'))));
|
||||
$warning = $warning->render();
|
||||
|
||||
$my_inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'revisionID = %d AND commentID IS NULL AND authorPHID = %s AND '.
|
||||
'changesetID IN (%Ld)',
|
||||
$this->revisionID,
|
||||
$user->getPHID(),
|
||||
mpull($changesets, 'getID'));
|
||||
$my_inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($user->getPHID(), $this->revisionID)
|
||||
->execute();
|
||||
|
||||
$visible_changesets = array();
|
||||
foreach ($inlines + $my_inlines as $inline) {
|
||||
|
@ -643,10 +640,9 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
return $inline_comments;
|
||||
}
|
||||
|
||||
$inline_comments = id(new DifferentialInlineComment())
|
||||
->loadAllWhere(
|
||||
'commentID in (%Ld)',
|
||||
$comment_ids);
|
||||
$inline_comments = id(new DifferentialInlineCommentQuery())
|
||||
->withCommentIDs($comment_ids)
|
||||
->execute();
|
||||
|
||||
$load_changesets = array();
|
||||
foreach ($inline_comments as $inline) {
|
||||
|
|
|
@ -116,10 +116,9 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
|
|||
|
||||
$inline_comments = array();
|
||||
if ($this->attachInlineComments) {
|
||||
$inline_comments = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
|
||||
$actor_phid,
|
||||
$revision->getID());
|
||||
$inline_comments = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($actor_phid, $revision->getID())
|
||||
->execute();
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Temporary wrapper for transitioning Differential to ApplicationTransactions.
|
||||
*/
|
||||
final class DifferentialInlineCommentQuery
|
||||
extends PhabricatorOffsetPagedQuery {
|
||||
|
||||
private $revisionIDs;
|
||||
private $notDraft;
|
||||
private $ids;
|
||||
private $commentIDs;
|
||||
|
||||
private $authorAndChangesetIDs;
|
||||
private $draftComments;
|
||||
private $draftsByAuthors;
|
||||
|
||||
public function withRevisionIDs(array $ids) {
|
||||
$this->revisionIDs = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNotDraft($not_draft) {
|
||||
$this->notDraft = $not_draft;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withCommentIDs(array $ids) {
|
||||
$this->commentIDs = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAuthorAndChangesetIDs($author_phid, array $ids) {
|
||||
$this->authorAndChangesetIDs = array($author_phid, $ids);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDraftComments($author_phid, $revision_id) {
|
||||
$this->draftComments = array($author_phid, $revision_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDraftsByAuthors(array $author_phids) {
|
||||
$this->draftsByAuthors = $author_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$table = new DifferentialInlineComment();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
public function executeOne() {
|
||||
return head($this->execute());
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->revisionIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'revisionID IN (%Ld)',
|
||||
$this->revisionIDs);
|
||||
}
|
||||
|
||||
if ($this->notDraft) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'commentID IS NOT NULL');
|
||||
}
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->commentIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'commentID in (%Ld)',
|
||||
$this->commentIDs);
|
||||
}
|
||||
|
||||
if ($this->authorAndChangesetIDs) {
|
||||
list($phid, $ids) = $this->authorAndChangesetIDs;
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'authorPHID = %s AND changesetID IN (%Ld)',
|
||||
$phid,
|
||||
$ids);
|
||||
}
|
||||
|
||||
if ($this->draftComments) {
|
||||
list($phid, $rev_id) = $this->draftComments;
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
|
||||
$phid,
|
||||
$rev_id);
|
||||
}
|
||||
|
||||
if ($this->draftsByAuthors) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'authorPHID IN (%Ls) AND commentID IS NULL',
|
||||
$this->draftsByAuthors);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
}
|
|
@ -492,9 +492,9 @@ final class DifferentialRevisionQuery {
|
|||
$this->draftRevisions[] = substr($draft->getDraftKey(), $len);
|
||||
}
|
||||
|
||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'commentID IS NULL AND authorPHID IN (%Ls)',
|
||||
$this->draftAuthors);
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftsByAuthors($this->draftAuthors)
|
||||
->execute();
|
||||
foreach ($inlines as $inline) {
|
||||
$this->draftRevisions[] = $inline->getRevisionID();
|
||||
}
|
||||
|
|
|
@ -57,11 +57,10 @@ final class DifferentialSearchIndexer
|
|||
->withRevisionIDs(array($rev->getID()))
|
||||
->execute();
|
||||
|
||||
$inlines = $rev->loadRelatives(
|
||||
new DifferentialInlineComment(),
|
||||
'revisionID',
|
||||
'getID',
|
||||
'(commentID IS NOT NULL)');
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withRevisionIDs(array($rev->getID()))
|
||||
->withNotDraft(true)
|
||||
->execute();
|
||||
|
||||
$touches = array();
|
||||
|
||||
|
|
|
@ -199,9 +199,9 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
$comment->delete();
|
||||
}
|
||||
|
||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'revisionID = %d',
|
||||
$this->getID());
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withRevisionIDs(array($this->getID()))
|
||||
->execute();
|
||||
foreach ($inlines as $inline) {
|
||||
$inline->delete();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue