1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Use standard handle loading in Releeph

Summary: Ref T3718. Move from unbatched / ad-hoc loading to standard stuff for handles.

Test Plan: Looked at some requests and saw no changes.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3718

Differential Revision: https://secure.phabricator.com/D8810
This commit is contained in:
epriestley 2014-04-18 17:52:32 -07:00
parent c7f5dc0208
commit fde4ccf9b2
10 changed files with 72 additions and 85 deletions

View file

@ -31,19 +31,6 @@ abstract class DifferentialCustomField
return parent::shouldEnableForRole($role); return parent::shouldEnableForRole($role);
} }
protected function renderHandleList(array $handles) {
if (!$handles) {
return null;
}
$out = array();
foreach ($handles as $handle) {
$out[] = $handle->renderLink();
}
return phutil_implode_html(phutil_tag('br'), $out);
}
public function getRequiredDiffPropertiesForRevisionView() { public function getRequiredDiffPropertiesForRevisionView() {
if ($this->getProxy()) { if ($this->getProxy()) {
return $this->getProxy()->getRequiredDiffPropertiesForRevisionView(); return $this->getProxy()->getRequiredDiffPropertiesForRevisionView();

View file

@ -11,24 +11,23 @@ final class ReleephAuthorFieldSpecification
return 'Author'; return 'Author';
} }
public function renderPropertyViewValue(array $handles) { public function getRequiredHandlePHIDsForPropertyView() {
$pull = $this->getReleephRequest(); $pull = $this->getReleephRequest();
$commit = $pull->loadPhabricatorRepositoryCommit(); $commit = $pull->loadPhabricatorRepositoryCommit();
if (!$commit) { if (!$commit) {
return null; return array();
} }
$author_phid = $commit->getAuthorPHID(); $author_phid = $commit->getAuthorPHID();
if (!$author_phid) { if (!$author_phid) {
return null; return array();
} }
$handle = id(new PhabricatorHandleQuery()) return array($author_phid);
->setViewer($this->getUser()) }
->withPHIDs(array($author_phid))
->executeOne();
return $handle->renderLink(); public function renderPropertyViewValue(array $handles) {
return $this->renderHandleList($handles);
} }
} }

View file

@ -10,25 +10,12 @@ final class ReleephDependsOnFieldSpecification
return pht('Depends On'); return pht('Depends On');
} }
public function getRequiredHandlePHIDsForPropertyView() {
return $this->getDependentRevisionPHIDs();
}
public function renderPropertyViewValue(array $handles) { public function renderPropertyViewValue(array $handles) {
$revision_phids = $this->getDependentRevisionPHIDs(); return $this->renderHandleList($handles);
if (!$revision_phids) {
return null;
}
$links = array();
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->getUser())
->withPHIDs($revision_phids)
->execute();
foreach ($revision_phids as $revision_phid) {
$links[] = id(clone $handles[$revision_phid])
// Hack to remove the strike-through rendering of diff links
->setStatus(null)
->renderLink();
}
return phutil_implode_html(phutil_tag('br'), $links);
} }
private function getDependentRevisionPHIDs() { private function getDependentRevisionPHIDs() {
@ -36,7 +23,7 @@ final class ReleephDependsOnFieldSpecification
->getReleephRequest() ->getReleephRequest()
->loadDifferentialRevision(); ->loadDifferentialRevision();
if (!$revision) { if (!$revision) {
return null; return array();
} }
return PhabricatorEdgeQuery::loadDestinationPHIDs( return PhabricatorEdgeQuery::loadDestinationPHIDs(

View file

@ -18,7 +18,7 @@ final class ReleephDiffSizeFieldSpecification
public function renderPropertyViewValue(array $handles) { public function renderPropertyViewValue(array $handles) {
$diff_rev = $this->getReleephRequest()->loadDifferentialRevision(); $diff_rev = $this->getReleephRequest()->loadDifferentialRevision();
if (!$diff_rev) { if (!$diff_rev) {
return ''; return null;
} }
$diffs = $diff_rev->loadRelatives( $diffs = $diff_rev->loadRelatives(

View file

@ -30,14 +30,6 @@ abstract class ReleephFieldSpecification
return $value; return $value;
} }
public function slowlyLoadHandle($phid) {
// TODO: Remove this, it's transitional as fields modernize.
return id(new PhabricatorHandleQuery())
->withPHIDs(array($phid))
->setViewer($this->getUser())
->executeOne();
}
abstract public function getName(); abstract public function getName();
/* -( Storage )------------------------------------------------------------ */ /* -( Storage )------------------------------------------------------------ */

View file

@ -11,6 +11,12 @@ final class ReleephIntentFieldSpecification
return 'Intent'; return 'Intent';
} }
public function getRequiredHandlePHIDsForPropertyView() {
$pull = $this->getReleephRequest();
$intents = $pull->getUserIntents();
return array_keys($intents);
}
public function renderPropertyViewValue(array $handles) { public function renderPropertyViewValue(array $handles) {
$pull = $this->getReleephRequest(); $pull = $this->getReleephRequest();
@ -21,16 +27,6 @@ final class ReleephIntentFieldSpecification
return null; return null;
} }
$user_phids = array_keys($intents);
if ($user_phids) {
$handles = id(new PhabricatorHandleQuery())
->withPHIDs($user_phids)
->setViewer(PhabricatorUser::getOmnipotentUser())
->execute();
} else {
$handles = array();
}
$pushers = array(); $pushers = array();
$others = array(); $others = array();

View file

@ -11,9 +11,15 @@ final class ReleephOriginalCommitFieldSpecification
return 'Commit'; return 'Commit';
} }
public function getRequiredHandlePHIDsForPropertyView() {
return array(
$this->getReleephRequest()->getRequestCommitPHID(),
);
}
public function renderPropertyViewValue(array $handles) { public function renderPropertyViewValue(array $handles) {
$pull = $this->getReleephRequest(); return $this->renderHandleList($handles);
return $this->slowlyLoadHandle($pull->getRequestCommitPHID())->renderLink();
} }
} }

View file

@ -11,13 +11,19 @@ final class ReleephRequestorFieldSpecification
return 'Requestor'; return 'Requestor';
} }
public function renderPropertyViewValue(array $handles) { public function getRequiredHandlePHIDsForPropertyView() {
$phids = array();
$phid = $this->getReleephRequest()->getRequestUserPHID(); $phid = $this->getReleephRequest()->getRequestUserPHID();
$handle = id(new PhabricatorHandleQuery()) if ($phid) {
->setViewer($this->getUser()) $phids[] = $phid;
->withPHIDs(array($phid)) }
->executeOne();
return $handle->renderLink(); return $phids;
}
public function renderPropertyViewValue(array $handles) {
return $this->renderHandleList($handles);
} }
public function shouldAppearOnCommitMessage() { public function shouldAppearOnCommitMessage() {

View file

@ -11,26 +11,19 @@ final class ReleephRevisionFieldSpecification
return 'Revision'; return 'Revision';
} }
public function renderPropertyViewValue(array $handles) { public function getRequiredHandlePHIDsForPropertyView() {
$phid = $this $phids = array();
->getReleephRequest()
->loadRequestCommitDiffPHID(); $phid = $this->getReleephRequest()->loadRequestCommitDiffPHID();
if (!$phid) { if ($phid) {
return null; $phids[] = $phid;
} }
$handles = $this->getReleephRequest()->getHandles(); return $phids;
$handle = $handles[$phid]; }
$link = $handle
// Hack to remove the strike-through rendering of diff links public function renderPropertyViewValue(array $handles) {
->setStatus(null) return $this->renderHandleList($handles);
->renderLink();
return phutil_tag(
'div',
array(
'class' => 'releeph-header-text-truncated',
),
$link);
} }
} }

View file

@ -5,6 +5,7 @@
* @task core Core Properties and Field Identity * @task core Core Properties and Field Identity
* @task proxy Field Proxies * @task proxy Field Proxies
* @task context Contextual Data * @task context Contextual Data
* @task render Rendering Utilities
* @task storage Field Storage * @task storage Field Storage
* @task edit Integration with Edit Views * @task edit Integration with Edit Views
* @task view Integration with Property Views * @task view Integration with Property Views
@ -467,6 +468,26 @@ abstract class PhabricatorCustomField {
} }
/* -( Rendering Utilities )------------------------------------------------ */
/**
* @task render
*/
protected function renderHandleList(array $handles) {
if (!$handles) {
return null;
}
$out = array();
foreach ($handles as $handle) {
$out[] = $handle->renderLink();
}
return phutil_implode_html(phutil_tag('br'), $out);
}
/* -( Storage )------------------------------------------------------------ */ /* -( Storage )------------------------------------------------------------ */