@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use the unified markup cache for Maniphest

Summary:
- See D2945.
- Drop `cache` field from ManiphestTransaction.
- Render task descriptions and transactions through PhabricatorMarkupEngine.
- Also pull the list of macros more lazily.

Test Plan:
- Verified transactions and transaction preview work correctly and interact with cache correctly.
- Verified tasks descriptions and task preview work correctly.
- Verified we don't hit the imagemacro table when we're rendering everything from cache anymore.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2946

+150 -54
+2
resources/sql/patches/maniphestxcache.sql
··· 1 + ALTER TABLE `{$NAMESPACE}_maniphest`.`maniphest_transaction` 2 + DROP `cache`;
+2 -22
scripts/util/purge_cache.php
··· 22 22 23 23 $purge_changesets = false; 24 24 $purge_differential = false; 25 - $purge_maniphest = false; 26 25 27 26 $args = array_slice($argv, 1); 28 27 if (!$args) { ··· 36 35 case '--all': 37 36 $purge_changesets = true; 38 37 $purge_differential = true; 39 - $purge_maniphest = true; 40 38 break; 41 39 case '--changesets': 42 40 $purge_changesets = true; ··· 51 49 break; 52 50 case '--differential': 53 51 $purge_differential = true; 54 - break; 55 - case '--maniphest': 56 - $purge_maniphest = true; 57 52 break; 58 53 case '--help': 59 54 return help(); ··· 98 93 echo "Done.\n"; 99 94 } 100 95 101 - if ($purge_maniphest) { 102 - echo "Purging Maniphest comment cache...\n"; 103 - $table = new ManiphestTransaction(); 104 - queryfx( 105 - $table->establishConnection('w'), 106 - 'UPDATE %T SET cache = NULL', 107 - $table->getTableName()); 108 - echo "Done.\n"; 109 - } 110 - 111 96 echo "Ok, caches purged.\n"; 112 97 113 98 function usage($message) { ··· 122 107 **SUMMARY** 123 108 124 109 **purge_cache.php** 125 - [--maniphest] 126 110 [--differential] 127 111 [--changesets [changeset_id ...]] 128 112 **purge_cache.php** --all ··· 136 120 syntax highlighting, you may want to purge the changeset cache (with 137 121 "--changesets") so your changes are reflected in older diffs. 138 122 139 - If you change Remarkup rules, you may want to purge the Maniphest or 140 - Differential comment caches ("--maniphest", "--differential") so older 141 - comments pick up the new rules. 123 + If you change Remarkup rules, you may want to purge the Differential 124 + comment caches ("--differential") so older comments pick up the new rules. 142 125 143 126 __--all__ 144 127 Purge all long-lived caches. ··· 150 133 151 134 __--differential__ 152 135 Purge Differential comment formatting cache. 153 - 154 - __--maniphest__: show this help 155 - Purge Maniphest comment formatting cache. 156 136 157 137 __--help__: show this help 158 138
+7 -2
src/applications/maniphest/controller/ManiphestTaskDescriptionPreviewController.php
··· 27 27 $request = $this->getRequest(); 28 28 $description = $request->getStr('description'); 29 29 30 - $engine = PhabricatorMarkupEngine::newManiphestMarkupEngine(); 30 + $task = new ManiphestTask(); 31 + $task->setDescription($description); 32 + 33 + $output = PhabricatorMarkupEngine::renderOneObject( 34 + $task, 35 + ManiphestTask::MARKUP_FIELD_DESCRIPTION); 31 36 32 37 $content = 33 38 '<div class="phabricator-remarkup">'. 34 - $engine->markupText($description). 39 + $output. 35 40 '</div>'; 36 41 37 42 return id(new AphrontAjaxResponse())
+10 -3
src/applications/maniphest/controller/ManiphestTaskDetailController.php
··· 88 88 $handles = id(new PhabricatorObjectHandleData($phids)) 89 89 ->loadHandles(); 90 90 91 - $engine = PhabricatorMarkupEngine::newManiphestMarkupEngine(); 92 - 93 91 $dict = array(); 94 92 $dict['Status'] = 95 93 '<strong>'. ··· 305 303 $headsup_panel->setActionList($action_list); 306 304 $headsup_panel->setProperties($dict); 307 305 306 + $engine = new PhabricatorMarkupEngine(); 307 + $engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION); 308 + foreach ($transactions as $xaction) { 309 + if ($xaction->hasComments()) { 310 + $engine->addObject($xaction, ManiphestTransaction::MARKUP_FIELD_BODY); 311 + } 312 + } 313 + $engine->process(); 314 + 308 315 $headsup_panel->appendChild( 309 316 '<div class="phabricator-remarkup">'. 310 - $engine->markupText($task->getDescription()). 317 + $engine->getOutput($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION). 311 318 '</div>'); 312 319 313 320 $transaction_types = ManiphestTransactionType::getTransactionTypeMap();
+3 -1
src/applications/maniphest/controller/ManiphestTransactionPreviewController.php
··· 119 119 $transactions = array(); 120 120 $transactions[] = $transaction; 121 121 122 - $engine = PhabricatorMarkupEngine::newManiphestMarkupEngine(); 122 + $engine = new PhabricatorMarkupEngine(); 123 + $engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY); 124 + $engine->process(); 123 125 124 126 $transaction_view = new ManiphestTransactionListView(); 125 127 $transaction_view->setTransactions($transactions);
+52 -1
src/applications/maniphest/storage/ManiphestTask.php
··· 19 19 /** 20 20 * @group maniphest 21 21 */ 22 - final class ManiphestTask extends ManiphestDAO { 22 + final class ManiphestTask extends ManiphestDAO 23 + implements PhabricatorMarkupInterface { 24 + 25 + const MARKUP_FIELD_DESCRIPTION = 'markup:desc'; 23 26 24 27 protected $phid; 25 28 protected $authorPHID; ··· 212 215 $table->getTableName(), 213 216 implode(', ', $sql)); 214 217 } 218 + } 219 + 220 + 221 + /* -( Markup Interface )--------------------------------------------------- */ 222 + 223 + 224 + /** 225 + * @task markup 226 + */ 227 + public function getMarkupFieldKey($field) { 228 + $hash = PhabricatorHash::digest($this->getMarkupText($field)); 229 + $id = $this->getID(); 230 + return "maniphest:T{$id}:{$field}:{$hash}"; 231 + } 232 + 233 + 234 + /** 235 + * @task markup 236 + */ 237 + public function getMarkupText($field) { 238 + return $this->getDescription(); 239 + } 240 + 241 + 242 + /** 243 + * @task markup 244 + */ 245 + public function newMarkupEngine($field) { 246 + return PhabricatorMarkupEngine::newManiphestMarkupEngine(); 247 + } 248 + 249 + 250 + /** 251 + * @task markup 252 + */ 253 + public function didMarkupText( 254 + $field, 255 + $output, 256 + PhutilMarkupEngine $engine) { 257 + return $output; 258 + } 259 + 260 + 261 + /** 262 + * @task markup 263 + */ 264 + public function shouldUseMarkupCache($field) { 265 + return (bool)$this->getID(); 215 266 } 216 267 217 268 }
+56 -2
src/applications/maniphest/storage/ManiphestTransaction.php
··· 17 17 */ 18 18 19 19 /** 20 + * @task markup Markup Interface 20 21 * @group maniphest 21 22 */ 22 - final class ManiphestTransaction extends ManiphestDAO { 23 + final class ManiphestTransaction extends ManiphestDAO 24 + implements PhabricatorMarkupInterface { 25 + 26 + const MARKUP_FIELD_BODY = 'markup:body'; 23 27 24 28 protected $taskID; 25 29 protected $authorPHID; ··· 27 31 protected $oldValue; 28 32 protected $newValue; 29 33 protected $comments; 30 - protected $cache; 31 34 protected $metadata = array(); 32 35 protected $contentSource; 33 36 ··· 141 144 142 145 public function getContentSource() { 143 146 return PhabricatorContentSource::newFromSerialized($this->contentSource); 147 + } 148 + 149 + 150 + /* -( Markup Interface )--------------------------------------------------- */ 151 + 152 + 153 + /** 154 + * @task markup 155 + */ 156 + public function getMarkupFieldKey($field) { 157 + if ($this->shouldUseMarkupCache($field)) { 158 + $id = $this->getID(); 159 + } else { 160 + $id = PhabricatorHash::digest($this->getMarkupText($field)); 161 + } 162 + return "maniphest:x:{$field}:{$id}"; 163 + } 164 + 165 + 166 + /** 167 + * @task markup 168 + */ 169 + public function getMarkupText($field) { 170 + return $this->getComments(); 171 + } 172 + 173 + 174 + /** 175 + * @task markup 176 + */ 177 + public function newMarkupEngine($field) { 178 + return PhabricatorMarkupEngine::newManiphestMarkupEngine(); 179 + } 180 + 181 + 182 + /** 183 + * @task markup 184 + */ 185 + public function didMarkupText( 186 + $field, 187 + $output, 188 + PhutilMarkupEngine $engine) { 189 + return $output; 190 + } 191 + 192 + 193 + /** 194 + * @task markup 195 + */ 196 + public function shouldUseMarkupCache($field) { 197 + return (bool)$this->getID(); 144 198 } 145 199 146 200 }
+5 -15
src/applications/maniphest/view/ManiphestTransactionDetailView.php
··· 57 57 return $this; 58 58 } 59 59 60 - public function setMarkupEngine(PhutilMarkupEngine $engine) { 60 + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 61 61 $this->markupEngine = $engine; 62 62 return $this; 63 63 } ··· 199 199 } 200 200 201 201 if ($comment_transaction && $comment_transaction->hasComments()) { 202 - $comments = $comment_transaction->getCache(); 203 - if (!strlen($comments)) { 204 - $comments = $comment_transaction->getComments(); 205 - if (strlen($comments)) { 206 - $comments = $this->markupEngine->markupText($comments); 207 - $comment_transaction->setCache($comments); 208 - if ($comment_transaction->getID() && !$this->preview) { 209 - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 210 - $comment_transaction->save(); 211 - unset($unguarded); 212 - } 213 - } 214 - } 202 + $comment_block = $this->markupEngine->getOutput( 203 + $comment_transaction, 204 + ManiphestTransaction::MARKUP_FIELD_BODY); 215 205 $comment_block = 216 206 '<div class="maniphest-transaction-comments phabricator-remarkup">'. 217 - $comments. 207 + $comment_block. 218 208 '</div>'; 219 209 } else { 220 210 $comment_block = null;
+1 -1
src/applications/maniphest/view/ManiphestTransactionListView.php
··· 45 45 return $this; 46 46 } 47 47 48 - public function setMarkupEngine(PhutilMarkupEngine $engine) { 48 + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 49 49 $this->markupEngine = $engine; 50 50 return $this; 51 51 }
+8 -7
src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php
··· 24 24 25 25 private $images = array(); 26 26 27 - public function __construct() { 28 - $rows = id(new PhabricatorFileImageMacro())->loadAll(); 29 - foreach ($rows as $row) { 30 - $this->images[$row->getName()] = $row->getFilePHID(); 31 - } 32 - } 33 - 34 27 public function apply($text) { 35 28 return preg_replace_callback( 36 29 '@^([a-zA-Z0-9_\-]+)$@m', ··· 39 32 } 40 33 41 34 public function markupImageMacro($matches) { 35 + if ($this->images === null) { 36 + $this->images = array(); 37 + $rows = id(new PhabricatorFileImageMacro())->loadAll(); 38 + foreach ($rows as $row) { 39 + $this->images[$row->getName()] = $row->getFilePHID(); 40 + } 41 + } 42 + 42 43 if (array_key_exists($matches[1], $this->images)) { 43 44 $phid = $this->images[$matches[1]]; 44 45
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 911 911 'type' => 'sql', 912 912 'name' => $this->getPatchPath('markupcache.sql'), 913 913 ), 914 + 'maniphestxcache.sql' => array( 915 + 'type' => 'sql', 916 + 'name' => $this->getPatchPath('maniphestxcache.sql'), 917 + ), 914 918 ); 915 919 } 916 920