Differential D19247 Diff 46086 src/applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryWorkingCopyVersion.php
Show All 22 Lines | return array( | ||||
'key_workingcopy' => array( | 'key_workingcopy' => array( | ||||
'columns' => array('repositoryPHID', 'devicePHID'), | 'columns' => array('repositoryPHID', 'devicePHID'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function getWriteProperty($key, $default = null) { | |||||
// The "writeProperties" don't currently get automatically serialized or | |||||
// deserialized. Perhaps they should. | |||||
try { | |||||
$properties = phutil_json_decode($this->writeProperties); | |||||
return idx($properties, $key, $default); | |||||
} catch (Exception $ex) { | |||||
return null; | |||||
} | |||||
} | |||||
public static function loadVersions($repository_phid) { | public static function loadVersions($repository_phid) { | ||||
$version = new self(); | $version = new self(); | ||||
$conn_w = $version->establishConnection('w'); | $conn_w = $version->establishConnection('w'); | ||||
$table = $version->getTableName(); | $table = $version->getTableName(); | ||||
// This is a normal read, but force it to come from the master. | // This is a normal read, but force it to come from the master. | ||||
$rows = queryfx_all( | $rows = queryfx_all( | ||||
$conn_w, | $conn_w, | ||||
'SELECT * FROM %T WHERE repositoryPHID = %s', | 'SELECT * FROM %T WHERE repositoryPHID = %s', | ||||
$table, | $table, | ||||
$repository_phid); | $repository_phid); | ||||
return $version->loadAllFromArray($rows); | return $version->loadAllFromArray($rows); | ||||
} | } | ||||
public static function loadWriter($repository_phid) { | |||||
$version = new self(); | |||||
$conn_w = $version->establishConnection('w'); | |||||
$table = $version->getTableName(); | |||||
// We're forcing this read to go to the master. | |||||
$row = queryfx_one( | |||||
$conn_w, | |||||
'SELECT * FROM %T WHERE repositoryPHID = %s AND isWriting = 1 | |||||
LIMIT 1', | |||||
$table, | |||||
$repository_phid); | |||||
if (!$row) { | |||||
return null; | |||||
} | |||||
return $version->loadFromArray($row); | |||||
} | |||||
public static function getReadLock($repository_phid, $device_phid) { | public static function getReadLock($repository_phid, $device_phid) { | ||||
$repository_hash = PhabricatorHash::digestForIndex($repository_phid); | $repository_hash = PhabricatorHash::digestForIndex($repository_phid); | ||||
$device_hash = PhabricatorHash::digestForIndex($device_phid); | $device_hash = PhabricatorHash::digestForIndex($device_phid); | ||||
$lock_key = "repo.read({$repository_hash}, {$device_hash})"; | $lock_key = "repo.read({$repository_hash}, {$device_hash})"; | ||||
return PhabricatorGlobalLock::newLock($lock_key); | return PhabricatorGlobalLock::newLock($lock_key); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |