Use the markup pipeline in Releeph

Summary: Use a single `PhabricatorMarkupEngine` to render any markup in Releeph's fields, rather than rendering everything from scratch every time.

Test Plan: Check out the "Services" tab in the dark console when rendering a page on a branch page with 500x RQs!

Reviewers: wez, epriestley

Reviewed By: epriestley

CC: epriestley, aran

Maniphest Tasks: T3098

Differential Revision: https://secure.phabricator.com/D5822
This commit is contained in:
Edward Speyer 2013-05-03 12:25:53 +01:00
parent 5c4a9ac9e5
commit 380f011fa1
4 changed files with 110 additions and 22 deletions

View file

@ -12,21 +12,12 @@ final class ReleephDiffMessageFieldSpecification
} }
public function renderValueForHeaderView() { public function renderValueForHeaderView() {
$commit_data = $this
->getReleephRequest()
->loadPhabricatorRepositoryCommitData();
if (!$commit_data) {
return '';
}
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$engine->setConfig('viewer', $this->getUser());
$markup = phutil_tag( $markup = phutil_tag(
'div', 'div',
array( array(
'class' => 'phabricator-remarkup', 'class' => 'phabricator-remarkup',
), ),
$engine->markupText($commit_data->getCommitMessage())); $this->getMarkupEngineOutput());
return id(new AphrontNoteView()) return id(new AphrontNoteView())
->setTitle('Commit Message') ->setTitle('Commit Message')
@ -34,4 +25,19 @@ final class ReleephDiffMessageFieldSpecification
->render(); ->render();
} }
public function shouldMarkup() {
return true;
}
public function getMarkupText($field) {
$commit_data = $this
->getReleephRequest()
->loadPhabricatorRepositoryCommitData();
if ($commit_data) {
return $commit_data->getCommitMessage();
} else {
return '';
}
}
} }

View file

@ -1,6 +1,7 @@
<?php <?php
abstract class ReleephFieldSpecification { abstract class ReleephFieldSpecification
implements PhabricatorMarkupInterface {
abstract public function getName(); abstract public function getName();
@ -239,6 +240,64 @@ abstract class ReleephFieldSpecification {
} }
/* -( Markup Interface )--------------------------------------------------- */
const MARKUP_FIELD_GENERIC = 'releeph:generic-markup-field';
private $engine;
/**
* ReleephFieldSpecification implements much of PhabricatorMarkupInterface
* for you. If you return true from `shouldMarkup()`, and implement
* `getMarkupText()` then your text will be rendered through the Phabricator
* markup pipeline.
*
* Output is retrievable with `getMarkupEngineOutput()`.
*/
public function shouldMarkup() {
return false;
}
public function getMarkupText($field) {
throw new ReleephFieldSpecificationIncompleteException($this);
}
final public function getMarkupEngineOutput() {
return $this->engine->getOutput($this, self::MARKUP_FIELD_GENERIC);
}
final public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
$this->engine = $engine;
$engine->addObject($this, self::MARKUP_FIELD_GENERIC);
return $this;
}
final public function getMarkupFieldKey($field) {
return sprintf(
'%s:%s:%s:%s',
$this->getReleephRequest()->getPHID(),
$this->getStorageKey(),
$field,
PhabricatorHash::digest($this->getMarkupText($field)));
}
final public function newMarkupEngine($field) {
return PhabricatorMarkupEngine::newDifferentialMarkupEngine();
}
final public function didMarkupText(
$field,
$output,
PhutilMarkupEngine $engine) {
return $output;
}
final public function shouldUseMarkupCache($field) {
return true;
}
/* -( Implementation )----------------------------------------------------- */ /* -( Implementation )----------------------------------------------------- */
protected function getRequiredStorageKey() { protected function getRequiredStorageKey() {

View file

@ -16,19 +16,12 @@ final class ReleephReasonFieldSpecification
} }
public function renderValueForHeaderView() { public function renderValueForHeaderView() {
$reason = $this->getValue();
if (!$reason) {
return '';
}
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$engine->setConfig('viewer', $this->getUser());
$markup = phutil_tag( $markup = phutil_tag(
'div', 'div',
array( array(
'class' => 'phabricator-remarkup', 'class' => 'phabricator-remarkup',
), ),
$engine->markupText($reason)); $this->getMarkupEngineOutput());
return id(new AphrontNoteView()) return id(new AphrontNoteView())
->setTitle('Reason') ->setTitle('Reason')
@ -75,4 +68,17 @@ final class ReleephReasonFieldSpecification
return $this->getValue(); return $this->getValue();
} }
public function shouldMarkup() {
return true;
}
public function getMarkupText($field) {
$reason = $this->getValue();
if ($reason) {
return $reason;
} else {
return '';
}
}
} }

View file

@ -90,10 +90,26 @@ final class ReleephRequestHeaderListView
} }
} }
$field_groups = $selector->arrangeFieldsForHeaderView($fields); $engine = id(new PhabricatorMarkupEngine())
->setViewer($this->getUser());
$views = array(); $views = array();
foreach ($this->releephRequests as $releeph_request) { foreach ($this->releephRequests as $releeph_request) {
$our_fields = array();
foreach ($fields as $key => $field) {
$our_fields[$key] = clone $field;
}
foreach ($our_fields as $field) {
if ($field->shouldMarkup()) {
$field
->setReleephRequest($releeph_request)
->setMarkupEngine($engine);
}
}
$our_field_groups = $selector->arrangeFieldsForHeaderView($our_fields);
$views[] = id(new ReleephRequestHeaderView()) $views[] = id(new ReleephRequestHeaderView())
->setUser($this->user) ->setUser($this->user)
->setAphrontRequest($this->aphrontRequest) ->setAphrontRequest($this->aphrontRequest)
@ -101,10 +117,11 @@ final class ReleephRequestHeaderListView
->setReleephProject($this->releephProject) ->setReleephProject($this->releephProject)
->setReleephBranch($this->releephBranch) ->setReleephBranch($this->releephBranch)
->setReleephRequest($releeph_request) ->setReleephRequest($releeph_request)
->setReleephFieldGroups($field_groups) ->setReleephFieldGroups($our_field_groups);
->render();
} }
$engine->process();
return $views; return $views;
} }