1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Make Changeset ID for render cache explicit

Summary:
DifferentialChangesetParser currently takes the Changeset object to mean a bunch
of different and mutually conflicting things implicitly:

  - Changeset ID is used to access the render cache.
  - Changeset ID is also used to tell the ajax endpoint what to render when
clicking "show more".
  - Changeset object has the actual changes.
  - Changeset ID and "oldChangesetID" are used to choose where to show inline
comments and how to attach new ones.

This indirectly causes a bunch of problems, like T141 and T132. Move toward
making all these separate things explicit. I want to have the changeset object
only mean the actual changes to display.

Test Plan:
Looked at changesets and verified the render cache was accessed correctly (and
not accessed in other cases).

Reviewed By: tuomaspelkonen
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, epriestley, tuomaspelkonen
Differential Revision: 228
This commit is contained in:
epriestley 2011-05-05 07:08:10 -07:00
parent 85b09c5ccb
commit af06bfb1cc
2 changed files with 37 additions and 6 deletions

View file

@ -48,6 +48,8 @@ class DifferentialChangesetViewController extends DifferentialController {
$right_new = true;
$left_source = $right->getID();
$left_new = false;
$render_cache_key = $right->getID();
} else if ($vs == -1) {
$right = null;
$left = $changeset;
@ -56,6 +58,8 @@ class DifferentialChangesetViewController extends DifferentialController {
$right_new = false;
$left_source = $left->getID();
$left_new = true;
$render_cache_key = null;
} else {
$right = $changeset;
$left = $vs_changeset;
@ -64,6 +68,8 @@ class DifferentialChangesetViewController extends DifferentialController {
$right_new = true;
$left_source = $left->getID();
$left_new = true;
$render_cache_key = null;
}
if ($left) {
@ -130,6 +136,7 @@ class DifferentialChangesetViewController extends DifferentialController {
$parser = new DifferentialChangesetParser();
$parser->setChangeset($changeset);
$parser->setRenderCacheKey($render_cache_key);
$parser->setRightSideCommentMapping($right_source, $right_new);
$parser->setLeftSideCommentMapping($left_source, $left_new);
$parser->setWhitespaceMode($request->getStr('whitespace'));

View file

@ -42,6 +42,8 @@ class DifferentialChangesetParser {
protected $oldChangesetID = null;
protected $noHighlight;
protected $renderCacheKey = null;
private $handles;
private $user;
@ -66,6 +68,28 @@ class DifferentialChangesetParser {
}
/**
* Set a key for identifying this changeset in the render cache. If set, the
* parser will attempt to use the changeset render cache, which can improve
* performance for frequently-viewed changesets.
*
* 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
*/
public function setRenderCacheKey($key) {
$this->renderCacheKey = $key;
return $this;
}
private function getRenderCacheKey() {
return $this->renderCacheKey;
}
public function setChangeset($changeset) {
$this->changeset = $changeset;
@ -427,7 +451,8 @@ class DifferentialChangesetParser {
}
public function loadCache() {
if (!$this->changesetID) {
$render_cache_key = $this->getRenderCacheKey();
if (!$render_cache_key) {
return false;
}
@ -439,7 +464,7 @@ class DifferentialChangesetParser {
$conn_r,
'SELECT * FROM %T WHERE id = %d',
$changeset->getTableName().'_parse_cache',
$this->changesetID);
$render_cache_key);
if (!$data) {
return false;
@ -488,7 +513,8 @@ class DifferentialChangesetParser {
}
public function saveCache() {
if (!$this->changesetID) {
$render_cache_key = $this->getRenderCacheKey();
if (!$render_cache_key) {
return false;
}
@ -516,7 +542,7 @@ class DifferentialChangesetParser {
'INSERT INTO %T (id, cache) VALUES (%d, %s)
ON DUPLICATE KEY UPDATE cache = VALUES(cache)',
$changeset->getTableName().'_parse_cache',
$this->changesetID,
$render_cache_key,
$cache);
} catch (AphrontQueryException $ex) {
// TODO: uhoh
@ -705,8 +731,6 @@ EOSYNTHETIC;
$this->tryCacheStuff();
$changeset_id = $this->changesetID;
$feedback_mask = array();
switch ($this->changeset->getFileType()) {