]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Upload binary files diffs in parallel
authorvrana <jakubv@fb.com>
Thu, 7 Feb 2013 04:24:31 +0000 (20:24 -0800)
committervrana <jakubv@fb.com>
Fri, 8 Feb 2013 01:27:36 +0000 (17:27 -0800)
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

index f6862cbd8cbd3a5b337d2f19084d9e117440cbdf..619322bba5f9b52a2db50ad29d24e86ffc75e4d8 100644 (file)
@@ -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();