mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 08:42:40 +01:00
Upload binary files diffs in parallel
Summary: Makes sense after D2471. Test Plan: Swapped two binary files, ran `arc diff --only`. Saw time 3.797 s instead of 4.361 s. Changed `file.upload` to `file.uploa`, saw proper error. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4847
This commit is contained in:
parent
46dfc64337
commit
7f9c286338
1 changed files with 33 additions and 25 deletions
|
@ -1090,27 +1090,28 @@ EOTEXT
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($changes as $change) {
|
||||
$upload_futures = array();
|
||||
|
||||
foreach ($changes as $key => $change) {
|
||||
if ($change->getFileType() != ArcanistDiffChangeType::FILE_BINARY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $change->getCurrentPath();
|
||||
|
||||
$name = basename($path);
|
||||
|
||||
$old_file = $change->getOriginalFileData();
|
||||
$old_dict = $this->uploadFile($old_file, $name, 'old binary');
|
||||
if ($old_dict['guid']) {
|
||||
$change->setMetadata('old:binary-phid', $old_dict['guid']);
|
||||
if ($old_dict['future']) {
|
||||
$upload_futures['old-'.$key] = $old_dict['future'];
|
||||
}
|
||||
$change->setMetadata('old:file:size', $old_dict['size']);
|
||||
$change->setMetadata('old:file:mime-type', $old_dict['mime']);
|
||||
|
||||
$new_file = $change->getCurrentFileData();
|
||||
$new_dict = $this->uploadFile($new_file, $name, 'new binary');
|
||||
if ($new_dict['guid']) {
|
||||
$change->setMetadata('new:binary-phid', $new_dict['guid']);
|
||||
if ($new_dict['future']) {
|
||||
$upload_futures['new-'.$key] = $new_dict['future'];
|
||||
}
|
||||
$change->setMetadata('new:file:size', $new_dict['size']);
|
||||
$change->setMetadata('new:file:mime-type', $new_dict['mime']);
|
||||
|
@ -1121,12 +1122,31 @@ EOTEXT
|
|||
}
|
||||
}
|
||||
|
||||
foreach (Futures($upload_futures)->limit(4) as $key => $future) {
|
||||
list($version, $key) = explode('-', $key, 2);
|
||||
$change = $changes[$key];
|
||||
$name = basename($change->getCurrentPath());
|
||||
|
||||
try {
|
||||
$guid = $future->resolve();
|
||||
$change->setMetadata($version.':binary-phid', $guid);
|
||||
} catch (Exception $e) {
|
||||
echo "Failed to upload {$version} binary '{$name}'.\n";
|
||||
|
||||
if (!phutil_console_confirm('Continue?', $default_no = false)) {
|
||||
throw new ArcanistUsageException(
|
||||
'Aborted due to file upload failure. You can use --skip-binaries '.
|
||||
'to skip binary uploads.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
private function uploadFile($data, $name, $desc) {
|
||||
$result = array(
|
||||
'guid' => null,
|
||||
'future' => null,
|
||||
'mime' => null,
|
||||
'size' => null
|
||||
);
|
||||
|
@ -1147,24 +1167,13 @@ EOTEXT
|
|||
|
||||
echo "Uploading {$desc} '{$name}' ({$mime_type}, {$size} bytes)...\n";
|
||||
|
||||
try {
|
||||
$guid = $this->getConduit()->callMethodSynchronous(
|
||||
$result['future'] = $this->getConduit()->callMethod(
|
||||
'file.upload',
|
||||
array(
|
||||
'data_base64' => base64_encode($data),
|
||||
'name' => $name,
|
||||
));
|
||||
|
||||
$result['guid'] = $guid;
|
||||
} catch (Exception $e) {
|
||||
echo "Failed to upload {$desc} '{$name}'.\n";
|
||||
|
||||
if (!phutil_console_confirm('Continue?', $default_no = false)) {
|
||||
throw new ArcanistUsageException(
|
||||
'Aborted due to file upload failure. You can use --skip-binaries '.
|
||||
'to skip binary uploads.');
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -1176,7 +1185,6 @@ EOTEXT
|
|||
'uuid' => null,
|
||||
);
|
||||
|
||||
$conduit = $this->getConduit();
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
|
||||
$parser = $this->newDiffParser();
|
||||
|
|
Loading…
Reference in a new issue