1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

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
This commit is contained in:
epriestley 2020-05-20 10:59:33 -07:00
parent 5d0ae283a9
commit 6d0dbeb77f
5 changed files with 30 additions and 14 deletions

View file

@ -0,0 +1 @@
DROP TABLE {$NAMESPACE}_differential.differential_changeset_parse_cache;

View file

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_differential.differential_changeset_parse_cache (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
cacheIndex BINARY(12) NOT NULL,
cache LONGBLOB NOT NULL,
dateCreated INT UNSIGNED NOT NULL,
UNIQUE KEY `key_cacheIndex` (cacheIndex)
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -295,8 +295,6 @@ final class DifferentialChangesetParser extends Phobject {
* By default, there is no render cache key and parsers do not use the cache.
* This is appropriate for rarely-viewed changesets.
*
* NOTE: Currently, this key must be a valid Differential Changeset ID.
*
* @param string Key for identifying this changeset in the render cache.
* @return this
*/
@ -376,9 +374,9 @@ final class DifferentialChangesetParser extends Phobject {
$conn_r = $changeset->establishConnection('r');
$data = queryfx_one(
$conn_r,
'SELECT * FROM %T WHERE id = %d',
$changeset->getTableName().'_parse_cache',
$render_cache_key);
'SELECT * FROM %T WHERE cacheIndex = %s',
DifferentialChangeset::TABLE_CACHE,
PhabricatorHash::digestForIndex($render_cache_key));
if (!$data) {
return false;
@ -480,12 +478,12 @@ final class DifferentialChangesetParser extends Phobject {
try {
queryfx(
$conn_w,
'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %B, %d)
'INSERT INTO %T (cacheIndex, cache, dateCreated) VALUES (%s, %B, %d)
ON DUPLICATE KEY UPDATE cache = VALUES(cache)',
DifferentialChangeset::TABLE_CACHE,
$render_cache_key,
PhabricatorHash::digestForIndex($render_cache_key),
$cache,
time());
PhabricatorTime::getNow());
} catch (AphrontQueryException $ex) {
// Ignore these exceptions. A common cause is that the cache is
// larger than 'max_allowed_packet', in which case we're better off

View file

@ -9,7 +9,8 @@ final class DifferentialSchemaSpec extends PhabricatorConfigSchemaSpec {
id(new DifferentialRevision())->getApplicationName(),
DifferentialChangeset::TABLE_CACHE,
array(
'id' => 'id',
'id' => 'auto',
'cacheIndex' => 'bytes12',
'cache' => 'bytes',
'dateCreated' => 'epoch',
),
@ -18,7 +19,11 @@ final class DifferentialSchemaSpec extends PhabricatorConfigSchemaSpec {
'columns' => array('id'),
'unique' => true,
),
'dateCreated' => array(
'key_cacheIndex' => array(
'columns' => array('cacheIndex'),
'unique' => true,
),
'key_created' => array(
'columns' => array('dateCreated'),
),
),

View file

@ -547,8 +547,6 @@ final class PHUIDiffInlineCommentDetailView
$changeset->setFilename($context->getFilename());
// TODO: This isn't cached!
$viewstate = new PhabricatorChangesetViewState();
$parser = id(new DifferentialChangesetParser())
@ -556,6 +554,15 @@ final class PHUIDiffInlineCommentDetailView
->setViewstate($viewstate)
->setChangeset($changeset);
$fragment = $inline->getInlineCommentCacheFragment();
if ($fragment !== null) {
$cache_key = sprintf(
'%s.suggestion-view(v1, %s)',
$fragment,
PhabricatorHash::digestForIndex($new_lines));
$parser->setRenderCacheKey($cache_key);
}
$renderer = new DifferentialChangesetOneUpRenderer();
$renderer->setSimpleMode(true);
@ -572,6 +579,4 @@ final class PHUIDiffInlineCommentDetailView
return $view;
}
}