Skip to content

Commit 5d8b75b

Browse files
author
epriestley
committed
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
1 parent eac8e0e commit 5d8b75b

11 files changed

+150
-54
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `{$NAMESPACE}_maniphest`.`maniphest_transaction`
2+
DROP `cache`;

scripts/util/purge_cache.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
$purge_changesets = false;
2424
$purge_differential = false;
25-
$purge_maniphest = false;
2625

2726
$args = array_slice($argv, 1);
2827
if (!$args) {
@@ -36,7 +35,6 @@
3635
case '--all':
3736
$purge_changesets = true;
3837
$purge_differential = true;
39-
$purge_maniphest = true;
4038
break;
4139
case '--changesets':
4240
$purge_changesets = true;
@@ -52,9 +50,6 @@
5250
case '--differential':
5351
$purge_differential = true;
5452
break;
55-
case '--maniphest':
56-
$purge_maniphest = true;
57-
break;
5853
case '--help':
5954
return help();
6055
default:
@@ -98,16 +93,6 @@
9893
echo "Done.\n";
9994
}
10095

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-
11196
echo "Ok, caches purged.\n";
11297

11398
function usage($message) {
@@ -122,7 +107,6 @@ function help() {
122107
**SUMMARY**
123108
124109
**purge_cache.php**
125-
[--maniphest]
126110
[--differential]
127111
[--changesets [changeset_id ...]]
128112
**purge_cache.php** --all
@@ -136,9 +120,8 @@ function help() {
136120
syntax highlighting, you may want to purge the changeset cache (with
137121
"--changesets") so your changes are reflected in older diffs.
138122
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.
142125
143126
__--all__
144127
Purge all long-lived caches.
@@ -151,9 +134,6 @@ function help() {
151134
__--differential__
152135
Purge Differential comment formatting cache.
153136
154-
__--maniphest__: show this help
155-
Purge Maniphest comment formatting cache.
156-
157137
__--help__: show this help
158138
159139

src/applications/maniphest/controller/ManiphestTaskDescriptionPreviewController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ public function processRequest() {
2727
$request = $this->getRequest();
2828
$description = $request->getStr('description');
2929

30-
$engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();
30+
$task = new ManiphestTask();
31+
$task->setDescription($description);
32+
33+
$output = PhabricatorMarkupEngine::renderOneObject(
34+
$task,
35+
ManiphestTask::MARKUP_FIELD_DESCRIPTION);
3136

3237
$content =
3338
'<div class="phabricator-remarkup">'.
34-
$engine->markupText($description).
39+
$output.
3540
'</div>';
3641

3742
return id(new AphrontAjaxResponse())

src/applications/maniphest/controller/ManiphestTaskDetailController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public function processRequest() {
8888
$handles = id(new PhabricatorObjectHandleData($phids))
8989
->loadHandles();
9090

91-
$engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();
92-
9391
$dict = array();
9492
$dict['Status'] =
9593
'<strong>'.
@@ -305,9 +303,18 @@ public function processRequest() {
305303
$headsup_panel->setActionList($action_list);
306304
$headsup_panel->setProperties($dict);
307305

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+
308315
$headsup_panel->appendChild(
309316
'<div class="phabricator-remarkup">'.
310-
$engine->markupText($task->getDescription()).
317+
$engine->getOutput($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION).
311318
'</div>');
312319

313320
$transaction_types = ManiphestTransactionType::getTransactionTypeMap();

src/applications/maniphest/controller/ManiphestTransactionPreviewController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public function processRequest() {
119119
$transactions = array();
120120
$transactions[] = $transaction;
121121

122-
$engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();
122+
$engine = new PhabricatorMarkupEngine();
123+
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
124+
$engine->process();
123125

124126
$transaction_view = new ManiphestTransactionListView();
125127
$transaction_view->setTransactions($transactions);

src/applications/maniphest/storage/ManiphestTask.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
/**
2020
* @group maniphest
2121
*/
22-
final class ManiphestTask extends ManiphestDAO {
22+
final class ManiphestTask extends ManiphestDAO
23+
implements PhabricatorMarkupInterface {
24+
25+
const MARKUP_FIELD_DESCRIPTION = 'markup:desc';
2326

2427
protected $phid;
2528
protected $authorPHID;
@@ -214,4 +217,52 @@ private function writeAuxiliaryUpdates() {
214217
}
215218
}
216219

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();
266+
}
267+
217268
}

src/applications/maniphest/storage/ManiphestTransaction.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
*/
1818

1919
/**
20+
* @task markup Markup Interface
2021
* @group maniphest
2122
*/
22-
final class ManiphestTransaction extends ManiphestDAO {
23+
final class ManiphestTransaction extends ManiphestDAO
24+
implements PhabricatorMarkupInterface {
25+
26+
const MARKUP_FIELD_BODY = 'markup:body';
2327

2428
protected $taskID;
2529
protected $authorPHID;
2630
protected $transactionType;
2731
protected $oldValue;
2832
protected $newValue;
2933
protected $comments;
30-
protected $cache;
3134
protected $metadata = array();
3235
protected $contentSource;
3336

@@ -143,4 +146,55 @@ public function getContentSource() {
143146
return PhabricatorContentSource::newFromSerialized($this->contentSource);
144147
}
145148

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();
198+
}
199+
146200
}

src/applications/maniphest/view/ManiphestTransactionDetailView.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function setHandles(array $handles) {
5757
return $this;
5858
}
5959

60-
public function setMarkupEngine(PhutilMarkupEngine $engine) {
60+
public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
6161
$this->markupEngine = $engine;
6262
return $this;
6363
}
@@ -199,22 +199,12 @@ public function render() {
199199
}
200200

201201
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);
215205
$comment_block =
216206
'<div class="maniphest-transaction-comments phabricator-remarkup">'.
217-
$comments.
207+
$comment_block.
218208
'</div>';
219209
} else {
220210
$comment_block = null;

src/applications/maniphest/view/ManiphestTransactionListView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function setUser(PhabricatorUser $user) {
4545
return $this;
4646
}
4747

48-
public function setMarkupEngine(PhutilMarkupEngine $engine) {
48+
public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
4949
$this->markupEngine = $engine;
5050
return $this;
5151
}

src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ final class PhabricatorRemarkupRuleImageMacro
2424

2525
private $images = array();
2626

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-
3427
public function apply($text) {
3528
return preg_replace_callback(
3629
'@^([a-zA-Z0-9_\-]+)$@m',
@@ -39,6 +32,14 @@ public function apply($text) {
3932
}
4033

4134
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+
4243
if (array_key_exists($matches[1], $this->images)) {
4344
$phid = $this->images[$matches[1]];
4445

src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ public function getPatches() {
911911
'type' => 'sql',
912912
'name' => $this->getPatchPath('markupcache.sql'),
913913
),
914+
'maniphestxcache.sql' => array(
915+
'type' => 'sql',
916+
'name' => $this->getPatchPath('maniphestxcache.sql'),
917+
),
914918
);
915919
}
916920

0 commit comments

Comments
 (0)