1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +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:
epriestley 2013-06-21 12:54:56 -07:00
parent 44302d2f07
commit 6a2ae07791
12 changed files with 165 additions and 41 deletions

View file

@ -370,6 +370,7 @@ phutil_register_library_map(array(
'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php', 'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php',
'DifferentialInlineCommentEditView' => 'applications/differential/view/DifferentialInlineCommentEditView.php', 'DifferentialInlineCommentEditView' => 'applications/differential/view/DifferentialInlineCommentEditView.php',
'DifferentialInlineCommentPreviewController' => 'applications/differential/controller/DifferentialInlineCommentPreviewController.php', 'DifferentialInlineCommentPreviewController' => 'applications/differential/controller/DifferentialInlineCommentPreviewController.php',
'DifferentialInlineCommentQuery' => 'applications/differential/query/DifferentialInlineCommentQuery.php',
'DifferentialInlineCommentView' => 'applications/differential/view/DifferentialInlineCommentView.php', 'DifferentialInlineCommentView' => 'applications/differential/view/DifferentialInlineCommentView.php',
'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/DifferentialLinesFieldSpecification.php', 'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/DifferentialLinesFieldSpecification.php',
'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/DifferentialLintFieldSpecification.php', 'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/DifferentialLintFieldSpecification.php',
@ -2249,6 +2250,7 @@ phutil_register_library_map(array(
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController', 'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
'DifferentialInlineCommentEditView' => 'AphrontView', 'DifferentialInlineCommentEditView' => 'AphrontView',
'DifferentialInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController', 'DifferentialInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController',
'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery',
'DifferentialInlineCommentView' => 'AphrontView', 'DifferentialInlineCommentView' => 'AphrontView',
'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',

View file

@ -40,9 +40,9 @@ final class ConduitAPI_differential_getrevisioncomments_Method
$with_inlines = $request->getValue('inlines'); $with_inlines = $request->getValue('inlines');
if ($with_inlines) { if ($with_inlines) {
$inlines = id(new DifferentialInlineComment())->loadAllWhere( $inlines = id(new DifferentialInlineCommentQuery())
'revisionID IN (%Ld)', ->withRevisionIDs($revision_ids)
$revision_ids); ->execute();
$changesets = array(); $changesets = array();
if ($inlines) { if ($inlines) {
$changesets = id(new DifferentialChangeset())->loadAllWhere( $changesets = id(new DifferentialChangeset())->loadAllWhere(

View file

@ -268,10 +268,9 @@ final class DifferentialChangesetViewController extends DifferentialController {
return; return;
} }
return id(new DifferentialInlineComment())->loadAllWhere( return id(new DifferentialInlineCommentQuery())
'changesetID IN (%Ld) AND (commentID IS NOT NULL OR authorPHID = %s)', ->withAuthorAndChangesetIDs($author_phid, $changeset_ids)
$changeset_ids, ->execute();
$author_phid);
} }
private function buildRawFileResponse( private function buildRawFileResponse(

View file

@ -39,10 +39,9 @@ final class DifferentialCommentSaveController extends DifferentialController {
->setAddedCCs($ccs) ->setAddedCCs($ccs)
->save(); ->save();
} catch (DifferentialActionHasNoEffectException $no_effect) { } catch (DifferentialActionHasNoEffectException $no_effect) {
$has_inlines = id(new DifferentialInlineComment())->loadAllWhere( $has_inlines = id(new DifferentialInlineCommentQuery())
'authorPHID = %s AND revisionID = %d AND commentID IS NULL', ->withDraftComments($request->getUser()->getPHID(), $revision->getID())
$request->getUser()->getPHID(), ->execute();
$revision->getID());
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
$dialog->setUser($request->getUser()); $dialog->setUser($request->getUser());

View file

@ -29,7 +29,9 @@ final class DifferentialInlineCommentEditController
} }
protected function loadComment($id) { protected function loadComment($id) {
return id(new DifferentialInlineComment())->load($id); return id(new DifferentialInlineCommentQuery())
->withIDs(array($id))
->executeOne();
} }
protected function loadCommentForEdit($id) { protected function loadCommentForEdit($id) {

View file

@ -12,10 +12,9 @@ extends PhabricatorInlineCommentPreviewController {
protected function loadInlineComments() { protected function loadInlineComments() {
$user = $this->getRequest()->getUser(); $user = $this->getRequest()->getUser();
$inlines = id(new DifferentialInlineComment())->loadAllWhere( $inlines = id(new DifferentialInlineCommentQuery())
'authorPHID = %s AND revisionID = %d AND commentID IS NULL', ->withDraftComments($user->getPHID(), $this->revisionID)
$user->getPHID(), ->execute();
$this->revisionID);
return $inlines; return $inlines;
} }

View file

@ -194,12 +194,9 @@ final class DifferentialRevisionViewController extends DifferentialController {
pht('Show All Files Inline')))); pht('Show All Files Inline'))));
$warning = $warning->render(); $warning = $warning->render();
$my_inlines = id(new DifferentialInlineComment())->loadAllWhere( $my_inlines = id(new DifferentialInlineCommentQuery())
'revisionID = %d AND commentID IS NULL AND authorPHID = %s AND '. ->withDraftComments($user->getPHID(), $this->revisionID)
'changesetID IN (%Ld)', ->execute();
$this->revisionID,
$user->getPHID(),
mpull($changesets, 'getID'));
$visible_changesets = array(); $visible_changesets = array();
foreach ($inlines + $my_inlines as $inline) { foreach ($inlines + $my_inlines as $inline) {
@ -643,10 +640,9 @@ final class DifferentialRevisionViewController extends DifferentialController {
return $inline_comments; return $inline_comments;
} }
$inline_comments = id(new DifferentialInlineComment()) $inline_comments = id(new DifferentialInlineCommentQuery())
->loadAllWhere( ->withCommentIDs($comment_ids)
'commentID in (%Ld)', ->execute();
$comment_ids);
$load_changesets = array(); $load_changesets = array();
foreach ($inline_comments as $inline) { foreach ($inline_comments as $inline) {

View file

@ -116,10 +116,9 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
$inline_comments = array(); $inline_comments = array();
if ($this->attachInlineComments) { if ($this->attachInlineComments) {
$inline_comments = id(new DifferentialInlineComment())->loadAllWhere( $inline_comments = id(new DifferentialInlineCommentQuery())
'authorPHID = %s AND revisionID = %d AND commentID IS NULL', ->withDraftComments($actor_phid, $revision->getID())
$actor_phid, ->execute();
$revision->getID());
} }
switch ($action) { switch ($action) {

View file

@ -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);
}
}

View file

@ -492,9 +492,9 @@ final class DifferentialRevisionQuery {
$this->draftRevisions[] = substr($draft->getDraftKey(), $len); $this->draftRevisions[] = substr($draft->getDraftKey(), $len);
} }
$inlines = id(new DifferentialInlineComment())->loadAllWhere( $inlines = id(new DifferentialInlineCommentQuery())
'commentID IS NULL AND authorPHID IN (%Ls)', ->withDraftsByAuthors($this->draftAuthors)
$this->draftAuthors); ->execute();
foreach ($inlines as $inline) { foreach ($inlines as $inline) {
$this->draftRevisions[] = $inline->getRevisionID(); $this->draftRevisions[] = $inline->getRevisionID();
} }

View file

@ -57,11 +57,10 @@ final class DifferentialSearchIndexer
->withRevisionIDs(array($rev->getID())) ->withRevisionIDs(array($rev->getID()))
->execute(); ->execute();
$inlines = $rev->loadRelatives( $inlines = id(new DifferentialInlineCommentQuery())
new DifferentialInlineComment(), ->withRevisionIDs(array($rev->getID()))
'revisionID', ->withNotDraft(true)
'getID', ->execute();
'(commentID IS NOT NULL)');
$touches = array(); $touches = array();

View file

@ -199,9 +199,9 @@ final class DifferentialRevision extends DifferentialDAO
$comment->delete(); $comment->delete();
} }
$inlines = id(new DifferentialInlineComment())->loadAllWhere( $inlines = id(new DifferentialInlineCommentQuery())
'revisionID = %d', ->withRevisionIDs(array($this->getID()))
$this->getID()); ->execute();
foreach ($inlines as $inline) { foreach ($inlines as $inline) {
$inline->delete(); $inline->delete();
} }