mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 17:52:43 +01:00
e96cd29eff
Summary: Fixes T8597. Second issue there is that if you look at a huge file in Diffusion (like `/path/to/300MB.pdf`) we pull the whole thing over Conduit upfront, then try to shove it into file storage. Instead, pull no more than the chunk limit (normally 4MB) and don't spend more than 10s pulling data. If we get 4MB of data and/or time out, just fail with a message in the vein of "this is a really big file". Eventually, we could improve this: - We can determine the //size// of very large files correctly in at least some VCSes, this just takes a little more work. This would let us show the true filesize, at least. - We could eventually stream the data out of the VCS, but we can't stream data over Conduit right now and this is a lot of work. This is just "stop crashing". Test Plan: Changed limits to 0.01 seconds and 8 bytes and saw reasonable errors. Changed them back and got normal beahvior. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8597 Differential Revision: https://secure.phabricator.com/D13348
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
final class DiffusionFileContentQueryConduitAPIMethod
|
|
extends DiffusionQueryConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'diffusion.filecontentquery';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Retrieve file content from a repository.');
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'array';
|
|
}
|
|
|
|
protected function defineCustomParamTypes() {
|
|
return array(
|
|
'path' => 'required string',
|
|
'commit' => 'required string',
|
|
'needsBlame' => 'optional bool',
|
|
'timeout' => 'optional int',
|
|
'byteLimit' => 'optional int',
|
|
);
|
|
}
|
|
|
|
protected function getResult(ConduitAPIRequest $request) {
|
|
$drequest = $this->getDiffusionRequest();
|
|
$needs_blame = $request->getValue('needsBlame');
|
|
$file_query = DiffusionFileContentQuery::newFromDiffusionRequest(
|
|
$drequest);
|
|
$file_query
|
|
->setViewer($request->getUser())
|
|
->setNeedsBlame($needs_blame);
|
|
|
|
$timeout = $request->getValue('timeout');
|
|
if ($timeout) {
|
|
$file_query->setTimeout($timeout);
|
|
}
|
|
|
|
$byte_limit = $request->getValue('byteLimit');
|
|
if ($byte_limit) {
|
|
$file_query->setByteLimit($byte_limit);
|
|
}
|
|
|
|
$file_content = $file_query->loadFileContent();
|
|
|
|
if ($needs_blame) {
|
|
list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData();
|
|
} else {
|
|
$text_list = $rev_list = $blame_dict = array();
|
|
}
|
|
|
|
$file_content
|
|
->setBlameDict($blame_dict)
|
|
->setRevList($rev_list)
|
|
->setTextList($text_list);
|
|
|
|
return $file_content->toDictionary();
|
|
}
|
|
|
|
}
|