Differential D10600 Diff 25539 src/applications/repository/storage/PhabricatorRepositoryBlameCache.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryBlameCache.php
- This file was added.
<?php | |||||
final class PhabricatorRepositoryBlameCache extends PhabricatorRepositoryDAO { | |||||
protected $pathId; | |||||
protected $commitId; | |||||
protected $blameDict; | |||||
public function getConfiguration() { | |||||
// FIXME: How do i configure this to not have an id column? | |||||
return array( | |||||
self::CONFIG_AUX_PHID => false, | |||||
self::CONFIG_TIMESTAMPS => false, | |||||
// self::CONFIG_IDS => self::IDS_MANUAL, | |||||
self::CONFIG_BINARY => array( | |||||
'blameDict' => true, | |||||
), | |||||
self::CONFIG_COLUMN_SCHEMA => array( | |||||
// 'id' => null, | |||||
'pathId' => 'uint32', | |||||
'commitId' => 'uint32', | |||||
'blameDict' => 'mediumblob', | |||||
), | |||||
self::CONFIG_KEY_SCHEMA => array( | |||||
'PRIMARY' => array( | |||||
'columns' => array('pathId', 'commitId'), | |||||
'unique' => true, | |||||
), | |||||
), | |||||
) + parent::getConfiguration(); | |||||
} | |||||
public function willWriteData(array &$data) { | |||||
$data['blameDict'] = gzcompress(implode(' ', $data['blameDict'])); | |||||
parent::willWriteData($data); | |||||
} | |||||
public function willReadData(array &$data) { | |||||
$data['blameDict'] = explode(' ', gzuncompress($data['blameDict'])); | |||||
parent::willReadData($data); | |||||
} | |||||
public static function saveToCache($path_id, $commit_id, $blame_dict) { | |||||
return id(new PhabricatorRepositoryBlameCache()) | |||||
->setPathId($path_id) | |||||
->setCommitId($commit_id) | |||||
->setBlameDict($blame_dict) | |||||
->replace(); | |||||
} | |||||
public static function loadFromCache($path_id, $commit_id) { | |||||
return id(new PhabricatorRepositoryBlameCache()) | |||||
->loadOneWhere('pathId = %d AND commitId = %d', $path_id, $commit_id); | |||||
} | |||||
} |