mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Make sure READMEs can hit the markup cache in Diffusion
Summary: Ref T2683. Normally not a big deal, but if a readme has some codeblocks missing the cache can slow things down. Test Plan: - Verified we hit the cache. - Verified TOC still works. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5028, T2683 Differential Revision: https://secure.phabricator.com/D9049
This commit is contained in:
parent
53e9df8a02
commit
cfa265f020
4 changed files with 47 additions and 12 deletions
|
@ -85,14 +85,25 @@ final class ConduitAPI_diffusion_readmequery_Method
|
|||
require_celerity_resource('syntax-highlighting-css');
|
||||
$class = 'remarkup-code';
|
||||
} else {
|
||||
// Markup extensionless files as remarkup so we get links and such.
|
||||
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
||||
$engine->setConfig('viewer', $request->getUser());
|
||||
$readme_content = $engine->markupText($readme_content);
|
||||
// TODO: This is sketchy, but make sure we hit the markup cache.
|
||||
$markup_object = id(new PhabricatorMarkupOneOff())
|
||||
->setEngineRuleset('diffusion-readme')
|
||||
->setContent($readme_content);
|
||||
$markup_field = 'default';
|
||||
|
||||
$readme_content = id(new PhabricatorMarkupEngine())
|
||||
->setViewer($request->getUser())
|
||||
->addObject($markup_object, $markup_field)
|
||||
->process()
|
||||
->getOutput($markup_object, $markup_field);
|
||||
|
||||
$engine = $markup_object->newMarkupEngine($markup_field);
|
||||
$toc = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents(
|
||||
$engine);
|
||||
if ($toc) {
|
||||
$toc = phutil_tag_div('phabricator-remarkup-toc', array(
|
||||
$toc = phutil_tag_div(
|
||||
'phabricator-remarkup-toc',
|
||||
array(
|
||||
phutil_tag_div(
|
||||
'phabricator-remarkup-toc-header',
|
||||
pht('Table of Contents')),
|
||||
|
|
|
@ -355,10 +355,17 @@ final class PhabricatorRepositoryGraphCache {
|
|||
// Build the actual data for the cache.
|
||||
foreach ($commit_ids as $commit_id) {
|
||||
$parent_ids = array();
|
||||
if (isset($parents[$commit_id])) {
|
||||
if (!empty($parents[$commit_id])) {
|
||||
foreach ($parents[$commit_id] as $row) {
|
||||
$parent_ids[] = (int)$row['parentCommitID'];
|
||||
}
|
||||
} else {
|
||||
// We expect all rows to have parents (commits with no parents get
|
||||
// an explicit "0" placeholder). If we're in an older repository, the
|
||||
// parent information might not have been populated yet. Decline to fill
|
||||
// the cache if we don't have the parent information, since the fill
|
||||
// will be incorrect.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($path_changes[$commit_id])) {
|
||||
|
|
|
@ -374,6 +374,11 @@ final class PhabricatorMarkupEngine {
|
|||
$engine = self::newMarkupEngine(array());
|
||||
$engine->setConfig('preserve-linebreaks', false);
|
||||
break;
|
||||
case 'diffusion-readme':
|
||||
$engine = self::newMarkupEngine(array());
|
||||
$engine->setConfig('preserve-linebreaks', false);
|
||||
$engine->setConfig('header.generate-toc', true);
|
||||
break;
|
||||
case 'diviner':
|
||||
$engine = self::newMarkupEngine(array());
|
||||
$engine->setConfig('preserve-linebreaks', false);
|
||||
|
|
|
@ -16,6 +16,16 @@ final class PhabricatorMarkupOneOff implements PhabricatorMarkupInterface {
|
|||
|
||||
private $content;
|
||||
private $preserveLinebreaks;
|
||||
private $engineRuleset;
|
||||
|
||||
public function setEngineRuleset($engine_ruleset) {
|
||||
$this->engineRuleset = $engine_ruleset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEngineRuleset() {
|
||||
return $this->engineRuleset;
|
||||
}
|
||||
|
||||
public function setPreserveLinebreaks($preserve_linebreaks) {
|
||||
$this->preserveLinebreaks = $preserve_linebreaks;
|
||||
|
@ -36,7 +46,9 @@ final class PhabricatorMarkupOneOff implements PhabricatorMarkupInterface {
|
|||
}
|
||||
|
||||
public function newMarkupEngine($field) {
|
||||
if ($this->preserveLinebreaks) {
|
||||
if ($this->engineRuleset) {
|
||||
return PhabricatorMarkupEngine::getEngine($this->engineRuleset);
|
||||
} else if ($this->preserveLinebreaks) {
|
||||
return PhabricatorMarkupEngine::getEngine();
|
||||
} else {
|
||||
return PhabricatorMarkupEngine::getEngine('nolinebreaks');
|
||||
|
|
Loading…
Reference in a new issue