Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/parser/DifferentialChangesetParser.php
Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | final class DifferentialChangesetParser extends Phobject { | ||||
/** | /** | ||||
* Set a key for identifying this changeset in the render cache. If set, the | * 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 | * parser will attempt to use the changeset render cache, which can improve | ||||
* performance for frequently-viewed changesets. | * performance for frequently-viewed changesets. | ||||
* | * | ||||
* By default, there is no render cache key and parsers do not use the cache. | * By default, there is no render cache key and parsers do not use the cache. | ||||
* This is appropriate for rarely-viewed changesets. | * 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. | * @param string Key for identifying this changeset in the render cache. | ||||
* @return this | * @return this | ||||
*/ | */ | ||||
public function setRenderCacheKey($key) { | public function setRenderCacheKey($key) { | ||||
$this->renderCacheKey = $key; | $this->renderCacheKey = $key; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | private function loadCache() { | ||||
} | } | ||||
$data = null; | $data = null; | ||||
$changeset = new DifferentialChangeset(); | $changeset = new DifferentialChangeset(); | ||||
$conn_r = $changeset->establishConnection('r'); | $conn_r = $changeset->establishConnection('r'); | ||||
$data = queryfx_one( | $data = queryfx_one( | ||||
$conn_r, | $conn_r, | ||||
'SELECT * FROM %T WHERE id = %d', | 'SELECT * FROM %T WHERE cacheIndex = %s', | ||||
$changeset->getTableName().'_parse_cache', | DifferentialChangeset::TABLE_CACHE, | ||||
$render_cache_key); | PhabricatorHash::digestForIndex($render_cache_key)); | ||||
if (!$data) { | if (!$data) { | ||||
return false; | return false; | ||||
} | } | ||||
if ($data['cache'][0] == '{') { | if ($data['cache'][0] == '{') { | ||||
// This is likely an old-style JSON cache which we will not be able to | // This is likely an old-style JSON cache which we will not be able to | ||||
// deserialize. | // deserialize. | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | public function saveCache() { | ||||
$changeset = new DifferentialChangeset(); | $changeset = new DifferentialChangeset(); | ||||
$conn_w = $changeset->establishConnection('w'); | $conn_w = $changeset->establishConnection('w'); | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
try { | try { | ||||
queryfx( | queryfx( | ||||
$conn_w, | $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)', | ON DUPLICATE KEY UPDATE cache = VALUES(cache)', | ||||
DifferentialChangeset::TABLE_CACHE, | DifferentialChangeset::TABLE_CACHE, | ||||
$render_cache_key, | PhabricatorHash::digestForIndex($render_cache_key), | ||||
$cache, | $cache, | ||||
time()); | PhabricatorTime::getNow()); | ||||
} catch (AphrontQueryException $ex) { | } catch (AphrontQueryException $ex) { | ||||
// Ignore these exceptions. A common cause is that the cache is | // Ignore these exceptions. A common cause is that the cache is | ||||
// larger than 'max_allowed_packet', in which case we're better off | // larger than 'max_allowed_packet', in which case we're better off | ||||
// not writing it. | // not writing it. | ||||
// TODO: It would be nice to tailor this more narrowly. | // TODO: It would be nice to tailor this more narrowly. | ||||
} | } | ||||
unset($unguarded); | unset($unguarded); | ||||
▲ Show 20 Lines • Show All 1,461 Lines • Show Last 20 Lines |