Skip to content

Commit 6d0dbeb

Browse files
author
epriestley
committedMay 20, 2020
Use the changeset parse cache to cache suggestion changesets
Summary: Ref T13513. Syntax highlighting is potentially expensive, and the changeset rendering pipeline can cache it. However, the cache is currently keyed ONLY by Differential changeset ID. Destroy the existing cache and rebuild it with a more standard cache key so it can be used in a more ad-hoc way by inline suggestion snippets. Test Plan: Used Darkconsole, saw cache hits and no more inline syntax highlighting for changesets with many inlines. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21280
1 parent 5d0ae28 commit 6d0dbeb

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE {$NAMESPACE}_differential.differential_changeset_parse_cache;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE {$NAMESPACE}_differential.differential_changeset_parse_cache (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
cacheIndex BINARY(12) NOT NULL,
4+
cache LONGBLOB NOT NULL,
5+
dateCreated INT UNSIGNED NOT NULL,
6+
UNIQUE KEY `key_cacheIndex` (cacheIndex)
7+
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

‎src/applications/differential/parser/DifferentialChangesetParser.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ public function diffOriginals() {
295295
* By default, there is no render cache key and parsers do not use the cache.
296296
* This is appropriate for rarely-viewed changesets.
297297
*
298-
* NOTE: Currently, this key must be a valid Differential Changeset ID.
299-
*
300298
* @param string Key for identifying this changeset in the render cache.
301299
* @return this
302300
*/
@@ -376,9 +374,9 @@ private function loadCache() {
376374
$conn_r = $changeset->establishConnection('r');
377375
$data = queryfx_one(
378376
$conn_r,
379-
'SELECT * FROM %T WHERE id = %d',
380-
$changeset->getTableName().'_parse_cache',
381-
$render_cache_key);
377+
'SELECT * FROM %T WHERE cacheIndex = %s',
378+
DifferentialChangeset::TABLE_CACHE,
379+
PhabricatorHash::digestForIndex($render_cache_key));
382380

383381
if (!$data) {
384382
return false;
@@ -480,12 +478,12 @@ public function saveCache() {
480478
try {
481479
queryfx(
482480
$conn_w,
483-
'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %B, %d)
481+
'INSERT INTO %T (cacheIndex, cache, dateCreated) VALUES (%s, %B, %d)
484482
ON DUPLICATE KEY UPDATE cache = VALUES(cache)',
485483
DifferentialChangeset::TABLE_CACHE,
486-
$render_cache_key,
484+
PhabricatorHash::digestForIndex($render_cache_key),
487485
$cache,
488-
time());
486+
PhabricatorTime::getNow());
489487
} catch (AphrontQueryException $ex) {
490488
// Ignore these exceptions. A common cause is that the cache is
491489
// larger than 'max_allowed_packet', in which case we're better off

‎src/applications/differential/storage/DifferentialSchemaSpec.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public function buildSchemata() {
99
id(new DifferentialRevision())->getApplicationName(),
1010
DifferentialChangeset::TABLE_CACHE,
1111
array(
12-
'id' => 'id',
12+
'id' => 'auto',
13+
'cacheIndex' => 'bytes12',
1314
'cache' => 'bytes',
1415
'dateCreated' => 'epoch',
1516
),
@@ -18,7 +19,11 @@ public function buildSchemata() {
1819
'columns' => array('id'),
1920
'unique' => true,
2021
),
21-
'dateCreated' => array(
22+
'key_cacheIndex' => array(
23+
'columns' => array('cacheIndex'),
24+
'unique' => true,
25+
),
26+
'key_created' => array(
2227
'columns' => array('dateCreated'),
2328
),
2429
),

‎src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,22 @@ private function newSuggestionView(PhabricatorInlineComment $inline) {
547547

548548
$changeset->setFilename($context->getFilename());
549549

550-
// TODO: This isn't cached!
551-
552550
$viewstate = new PhabricatorChangesetViewState();
553551

554552
$parser = id(new DifferentialChangesetParser())
555553
->setViewer($viewer)
556554
->setViewstate($viewstate)
557555
->setChangeset($changeset);
558556

557+
$fragment = $inline->getInlineCommentCacheFragment();
558+
if ($fragment !== null) {
559+
$cache_key = sprintf(
560+
'%s.suggestion-view(v1, %s)',
561+
$fragment,
562+
PhabricatorHash::digestForIndex($new_lines));
563+
$parser->setRenderCacheKey($cache_key);
564+
}
565+
559566
$renderer = new DifferentialChangesetOneUpRenderer();
560567
$renderer->setSimpleMode(true);
561568

@@ -572,6 +579,4 @@ private function newSuggestionView(PhabricatorInlineComment $inline) {
572579

573580
return $view;
574581
}
575-
576-
577582
}

0 commit comments

Comments
 (0)
Failed to load comments.