1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-17 01:08:41 +01:00

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() {
$commit_data = $this
->getReleephRequest()
->loadPhabricatorRepositoryCommitData();
if (!$commit_data) {
return '';
}
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$engine->setConfig('viewer', $this->getUser());
$markup = phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$engine->markupText($commit_data->getCommitMessage()));
$this->getMarkupEngineOutput());
return id(new AphrontNoteView())
->setTitle('Commit Message')
@ -34,4 +25,19 @@ final class ReleephDiffMessageFieldSpecification
->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
abstract class ReleephFieldSpecification {
abstract class ReleephFieldSpecification
implements PhabricatorMarkupInterface {
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 )----------------------------------------------------- */
protected function getRequiredStorageKey() {

View file

@ -16,19 +16,12 @@ final class ReleephReasonFieldSpecification
}
public function renderValueForHeaderView() {
$reason = $this->getValue();
if (!$reason) {
return '';
}
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$engine->setConfig('viewer', $this->getUser());
$markup = phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$engine->markupText($reason));
$this->getMarkupEngineOutput());
return id(new AphrontNoteView())
->setTitle('Reason')
@ -75,4 +68,17 @@ final class ReleephReasonFieldSpecification
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();
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())
->setUser($this->user)
->setAphrontRequest($this->aphrontRequest)
@ -101,10 +117,11 @@ final class ReleephRequestHeaderListView
->setReleephProject($this->releephProject)
->setReleephBranch($this->releephBranch)
->setReleephRequest($releeph_request)
->setReleephFieldGroups($field_groups)
->render();
->setReleephFieldGroups($our_field_groups);
}
$engine->process();
return $views;
}