Page MenuHomePhabricator

D16458.diff
No OneTemporary

D16458.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -656,6 +656,7 @@
'DiffusionExternalSymbolsSource' => 'applications/diffusion/symbol/DiffusionExternalSymbolsSource.php',
'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionFileContentQuery.php',
'DiffusionFileContentQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php',
+ 'DiffusionFileFutureQuery' => 'applications/diffusion/query/DiffusionFileFutureQuery.php',
'DiffusionFindSymbolsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php',
'DiffusionGetLintMessagesConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php',
'DiffusionGetRecentCommitsByPathConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php',
@@ -5149,8 +5150,9 @@
'DiffusionExternalController' => 'DiffusionController',
'DiffusionExternalSymbolQuery' => 'Phobject',
'DiffusionExternalSymbolsSource' => 'Phobject',
- 'DiffusionFileContentQuery' => 'DiffusionQuery',
+ 'DiffusionFileContentQuery' => 'DiffusionFileFutureQuery',
'DiffusionFileContentQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
+ 'DiffusionFileFutureQuery' => 'DiffusionQuery',
'DiffusionFindSymbolsConduitAPIMethod' => 'DiffusionConduitAPIMethod',
'DiffusionGetLintMessagesConduitAPIMethod' => 'DiffusionConduitAPIMethod',
'DiffusionGetRecentCommitsByPathConduitAPIMethod' => 'DiffusionConduitAPIMethod',
diff --git a/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
@@ -19,48 +19,14 @@
return array(
'path' => 'required string',
'commit' => 'required string',
- 'timeout' => 'optional int',
- 'byteLimit' => 'optional int',
- );
+ ) + DiffusionFileFutureQuery::getConduitParameters();
}
protected function getResult(ConduitAPIRequest $request) {
$drequest = $this->getDiffusionRequest();
- $file_query = DiffusionFileContentQuery::newFromDiffusionRequest($drequest);
-
- $timeout = $request->getValue('timeout');
- if ($timeout) {
- $file_query->setTimeout($timeout);
- }
-
- $byte_limit = $request->getValue('byteLimit');
- if ($byte_limit) {
- $file_query->setByteLimit($byte_limit);
- }
-
- $file = $file_query->execute();
-
- $too_slow = (bool)$file_query->getExceededTimeLimit();
- $too_huge = (bool)$file_query->getExceededByteLimit();
-
- $file_phid = null;
- if (!$too_slow && !$too_huge) {
- $repository = $drequest->getRepository();
- $repository_phid = $repository->getPHID();
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $file->attachToObject($repository_phid);
- unset($unguarded);
-
- $file_phid = $file->getPHID();
- }
-
- return array(
- 'tooSlow' => $too_slow,
- 'tooHuge' => $too_huge,
- 'filePHID' => $file_phid,
- );
+ return DiffusionFileContentQuery::newFromDiffusionRequest($drequest)
+ ->respondToConduitRequest($request);
}
}
diff --git a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php b/src/applications/diffusion/query/DiffusionFileFutureQuery.php
copy from src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
copy to src/applications/diffusion/query/DiffusionFileFutureQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/DiffusionFileFutureQuery.php
@@ -1,6 +1,7 @@
<?php
-abstract class DiffusionFileContentQuery extends DiffusionQuery {
+abstract class DiffusionFileFutureQuery
+ extends DiffusionQuery {
private $timeout;
private $byteLimit;
@@ -8,6 +9,13 @@
private $didHitByteLimit = false;
private $didHitTimeLimit = false;
+ public static function getConduitParameters() {
+ return array(
+ 'timeout' => 'optional int',
+ 'byteLimit' => 'optional int',
+ );
+ }
+
public function setTimeout($timeout) {
$this->timeout = $timeout;
return $this;
@@ -26,11 +34,6 @@
return $this->byteLimit;
}
- final public static function newFromDiffusionRequest(
- DiffusionRequest $request) {
- return parent::newQueryObject(__CLASS__, $request);
- }
-
final public function getExceededByteLimit() {
return $this->didHitByteLimit;
}
@@ -40,20 +43,53 @@
}
abstract protected function getFileContentFuture();
- abstract protected function resolveFileContentFuture(Future $future);
- final protected function executeQuery() {
- $future = $this->getFileContentFuture();
+ final public function respondToConduitRequest(ConduitAPIRequest $request) {
+ $drequest = $this->getRequest();
- if ($this->getTimeout()) {
- $future->setTimeout($this->getTimeout());
+ $timeout = $request->getValue('timeout');
+ if ($timeout) {
+ $this->setTimeout($timeout);
}
- $byte_limit = $this->getByteLimit();
+ $byte_limit = $request->getValue('byteLimit');
if ($byte_limit) {
- $future->setStdoutSizeLimit($byte_limit + 1);
+ $this->setByteLimit($byte_limit);
}
+ $file = $this->execute();
+
+ $too_slow = (bool)$this->getExceededTimeLimit();
+ $too_huge = (bool)$this->getExceededByteLimit();
+
+ $file_phid = null;
+ if (!$too_slow && !$too_huge) {
+ $repository = $drequest->getRepository();
+ $repository_phid = $repository->getPHID();
+
+ $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ $file->attachToObject($repository_phid);
+ unset($unguarded);
+
+ $file_phid = $file->getPHID();
+ }
+
+ return array(
+ 'tooSlow' => $too_slow,
+ 'tooHuge' => $too_huge,
+ 'filePHID' => $file_phid,
+ );
+ }
+
+ final public function executeInline() {
+ $future = $this->getFileContentFuture();
+ list($stdout) = $future->resolvex();
+ return $future;
+ }
+
+ final protected function executeQuery() {
+ $future = $this->newConfiguredFileContentFuture();
+
$drequest = $this->getRequest();
$name = basename($drequest->getPath());
@@ -82,6 +118,8 @@
$file = null;
}
+ $byte_limit = $this->getByteLimit();
+
if ($byte_limit && ($file->getByteSize() > $byte_limit)) {
$this->didHitByteLimit = true;
@@ -96,4 +134,20 @@
return $file;
}
+ private function newConfiguredFileContentFuture() {
+ $future = $this->getFileContentFuture();
+
+ if ($this->getTimeout()) {
+ $future->setTimeout($this->getTimeout());
+ }
+
+ $byte_limit = $this->getByteLimit();
+ if ($byte_limit) {
+ $future->setStdoutSizeLimit($byte_limit + 1);
+ }
+
+ return $future;
+ }
+
+
}
diff --git a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
@@ -1,99 +1,11 @@
<?php
-abstract class DiffusionFileContentQuery extends DiffusionQuery {
-
- private $timeout;
- private $byteLimit;
-
- private $didHitByteLimit = false;
- private $didHitTimeLimit = false;
-
- public function setTimeout($timeout) {
- $this->timeout = $timeout;
- return $this;
- }
-
- public function getTimeout() {
- return $this->timeout;
- }
-
- public function setByteLimit($byte_limit) {
- $this->byteLimit = $byte_limit;
- return $this;
- }
-
- public function getByteLimit() {
- return $this->byteLimit;
- }
+abstract class DiffusionFileContentQuery
+ extends DiffusionFileFutureQuery {
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
return parent::newQueryObject(__CLASS__, $request);
}
- final public function getExceededByteLimit() {
- return $this->didHitByteLimit;
- }
-
- final public function getExceededTimeLimit() {
- return $this->didHitTimeLimit;
- }
-
- abstract protected function getFileContentFuture();
- abstract protected function resolveFileContentFuture(Future $future);
-
- final protected function executeQuery() {
- $future = $this->getFileContentFuture();
-
- if ($this->getTimeout()) {
- $future->setTimeout($this->getTimeout());
- }
-
- $byte_limit = $this->getByteLimit();
- if ($byte_limit) {
- $future->setStdoutSizeLimit($byte_limit + 1);
- }
-
- $drequest = $this->getRequest();
-
- $name = basename($drequest->getPath());
- $ttl = PhabricatorTime::getNow() + phutil_units('48 hours in seconds');
-
- try {
- $threshold = PhabricatorFileStorageEngine::getChunkThreshold();
- $future->setReadBufferSize($threshold);
-
- $source = id(new PhabricatorExecFutureFileUploadSource())
- ->setName($name)
- ->setTTL($ttl)
- ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)
- ->setExecFuture($future);
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $file = $source->uploadFile();
- unset($unguarded);
-
- } catch (CommandException $ex) {
- if (!$future->getWasKilledByTimeout()) {
- throw $ex;
- }
-
- $this->didHitTimeLimit = true;
- $file = null;
- }
-
- if ($byte_limit && ($file->getByteSize() > $byte_limit)) {
- $this->didHitByteLimit = true;
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- id(new PhabricatorDestructionEngine())
- ->destroyObject($file);
- unset($unguarded);
-
- $file = null;
- }
-
- return $file;
- }
-
}
diff --git a/src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php
@@ -15,9 +15,4 @@
$path);
}
- protected function resolveFileContentFuture(Future $future) {
- list($corpus) = $future->resolvex();
- return $corpus;
- }
-
}
diff --git a/src/applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php
@@ -16,9 +16,4 @@
$path);
}
- protected function resolveFileContentFuture(Future $future) {
- list($corpus) = $future->resolvex();
- return $corpus;
- }
-
}
diff --git a/src/applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php
@@ -14,9 +14,4 @@
$repository->getSubversionPathURI($path, $commit));
}
- protected function resolveFileContentFuture(Future $future) {
- list($corpus) = $future->resolvex();
- return $corpus;
- }
-
}

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 21, 12:46 AM (4 w, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711805
Default Alt Text
D16458.diff (11 KB)

Event Timeline