@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

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

+30 -14
+1
resources/sql/autopatches/20200520.inline.01.remcache.sql
··· 1 + DROP TABLE {$NAMESPACE}_differential.differential_changeset_parse_cache;
+7
resources/sql/autopatches/20200520.inline.02.addcache.sql
··· 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};
+6 -8
src/applications/differential/parser/DifferentialChangesetParser.php
··· 295 295 * By default, there is no render cache key and parsers do not use the cache. 296 296 * This is appropriate for rarely-viewed changesets. 297 297 * 298 - * NOTE: Currently, this key must be a valid Differential Changeset ID. 299 - * 300 298 * @param string Key for identifying this changeset in the render cache. 301 299 * @return this 302 300 */ ··· 376 374 $conn_r = $changeset->establishConnection('r'); 377 375 $data = queryfx_one( 378 376 $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)); 382 380 383 381 if (!$data) { 384 382 return false; ··· 480 478 try { 481 479 queryfx( 482 480 $conn_w, 483 - 'INSERT INTO %T (id, cache, dateCreated) VALUES (%d, %B, %d) 481 + 'INSERT INTO %T (cacheIndex, cache, dateCreated) VALUES (%s, %B, %d) 484 482 ON DUPLICATE KEY UPDATE cache = VALUES(cache)', 485 483 DifferentialChangeset::TABLE_CACHE, 486 - $render_cache_key, 484 + PhabricatorHash::digestForIndex($render_cache_key), 487 485 $cache, 488 - time()); 486 + PhabricatorTime::getNow()); 489 487 } catch (AphrontQueryException $ex) { 490 488 // Ignore these exceptions. A common cause is that the cache is 491 489 // larger than 'max_allowed_packet', in which case we're better off
+7 -2
src/applications/differential/storage/DifferentialSchemaSpec.php
··· 9 9 id(new DifferentialRevision())->getApplicationName(), 10 10 DifferentialChangeset::TABLE_CACHE, 11 11 array( 12 - 'id' => 'id', 12 + 'id' => 'auto', 13 + 'cacheIndex' => 'bytes12', 13 14 'cache' => 'bytes', 14 15 'dateCreated' => 'epoch', 15 16 ), ··· 18 19 'columns' => array('id'), 19 20 'unique' => true, 20 21 ), 21 - 'dateCreated' => array( 22 + 'key_cacheIndex' => array( 23 + 'columns' => array('cacheIndex'), 24 + 'unique' => true, 25 + ), 26 + 'key_created' => array( 22 27 'columns' => array('dateCreated'), 23 28 ), 24 29 ),
+9 -4
src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php
··· 547 547 548 548 $changeset->setFilename($context->getFilename()); 549 549 550 - // TODO: This isn't cached! 551 - 552 550 $viewstate = new PhabricatorChangesetViewState(); 553 551 554 552 $parser = id(new DifferentialChangesetParser()) 555 553 ->setViewer($viewer) 556 554 ->setViewstate($viewstate) 557 555 ->setChangeset($changeset); 556 + 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 + } 558 565 559 566 $renderer = new DifferentialChangesetOneUpRenderer(); 560 567 $renderer->setSimpleMode(true); ··· 572 579 573 580 return $view; 574 581 } 575 - 576 - 577 582 }