From 7f9c286338b81f95998a4b308b1412b42c1b7436 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 6 Feb 2013 20:24:31 -0800 Subject: [PATCH] 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 --- src/workflow/ArcanistDiffWorkflow.php | 58 +++++++++++++++------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index f6862cbd..619322bb 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -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( - 'file.upload', - array( - 'data_base64' => base64_encode($data), - 'name' => $name, - )); - - $result['guid'] = $guid; - } catch (Exception $e) { - echo "Failed to upload {$desc} '{$name}'.\n"; + $result['future'] = $this->getConduit()->callMethod( + 'file.upload', + array( + 'data_base64' => base64_encode($data), + 'name' => $name, + )); - 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(); -- 2.43.0