mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Don't let blame run for longer than 15 seconds
Summary: Fixes T2450. If we spend more than 15 seconds in blame, just cut it off. Test Plan: - Changed timeout to 0.01 seconds. - Did blame on a non-highlighted file, got no blame, saw warning. - Did blame on a highlighted file, got no blame. - Note: you don't get a warning here because of Ajax stuff. It'd be kind of tricky to add and doesn't seem like a big deal so I'm planning to leave it as-is for now. Reviewers: chad Reviewed By: chad Subscribers: 20after4, chasemp Maniphest Tasks: T2450 Differential Revision: https://secure.phabricator.com/D14964
This commit is contained in:
parent
9ab1b5a22d
commit
438100691d
1 changed files with 35 additions and 10 deletions
|
@ -591,19 +591,27 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
$data) {
|
$data) {
|
||||||
|
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
$blame_timeout = 15;
|
||||||
|
$blame_failed = false;
|
||||||
|
|
||||||
if ($needs_blame) {
|
$file_corpus = $file_content->getCorpus();
|
||||||
$blame = $this->loadBlame($path, $drequest->getCommit());
|
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
||||||
|
$blame_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
||||||
|
$can_highlight = (strlen($file_corpus) <= $highlight_limit);
|
||||||
|
$can_blame = (strlen($file_corpus) <= $blame_limit);
|
||||||
|
|
||||||
|
if ($needs_blame && $can_blame) {
|
||||||
|
$blame = $this->loadBlame($path, $drequest->getCommit(), $blame_timeout);
|
||||||
list($blame_list, $blame_commits) = $blame;
|
list($blame_list, $blame_commits) = $blame;
|
||||||
|
if ($blame_list === null) {
|
||||||
|
$blame_failed = true;
|
||||||
|
$blame_list = array();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$blame_list = array();
|
$blame_list = array();
|
||||||
$blame_commits = array();
|
$blame_commits = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_corpus = $file_content->getCorpus();
|
|
||||||
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
|
||||||
$can_highlight = (strlen($file_corpus) <= $highlight_limit);
|
|
||||||
|
|
||||||
if (!$show_color) {
|
if (!$show_color) {
|
||||||
$corpus = $this->renderPlaintextCorpus(
|
$corpus = $this->renderPlaintextCorpus(
|
||||||
$file_corpus,
|
$file_corpus,
|
||||||
|
@ -697,16 +705,32 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
->appendChild($corpus)
|
->appendChild($corpus)
|
||||||
->setCollapsed(true);
|
->setCollapsed(true);
|
||||||
|
|
||||||
|
$messages = array();
|
||||||
|
|
||||||
if (!$can_highlight) {
|
if (!$can_highlight) {
|
||||||
$message = pht(
|
$messages[] = pht(
|
||||||
'This file is larger than %s, so syntax highlighting is disabled '.
|
'This file is larger than %s, so syntax highlighting is disabled '.
|
||||||
'by default.',
|
'by default.',
|
||||||
phutil_format_bytes($highlight_limit));
|
phutil_format_bytes($highlight_limit));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show_blame && !$can_blame) {
|
||||||
|
$messages[] = pht(
|
||||||
|
'This file is larger than %s, so blame is disabled.',
|
||||||
|
phutil_format_bytes($blame_limit));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($blame_failed) {
|
||||||
|
$messages[] = pht(
|
||||||
|
'Failed to load blame information for this file in %s second(s).',
|
||||||
|
new PhutilNumber($blame_timeout));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($messages) {
|
||||||
$corpus->setInfoView(
|
$corpus->setInfoView(
|
||||||
id(new PHUIInfoView())
|
id(new PHUIInfoView())
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
|
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
|
||||||
->setErrors(array($message)));
|
->setErrors($messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $corpus;
|
return $corpus;
|
||||||
|
@ -1709,15 +1733,16 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadBlame($path, $commit) {
|
private function loadBlame($path, $commit, $timeout) {
|
||||||
$blame = $this->callConduitWithDiffusionRequest(
|
$blame = $this->callConduitWithDiffusionRequest(
|
||||||
'diffusion.blame',
|
'diffusion.blame',
|
||||||
array(
|
array(
|
||||||
'commit' => $commit,
|
'commit' => $commit,
|
||||||
'paths' => array($path),
|
'paths' => array($path),
|
||||||
|
'timeout' => $timeout,
|
||||||
));
|
));
|
||||||
|
|
||||||
$identifiers = idx($blame, $path, array());
|
$identifiers = idx($blame, $path, null);
|
||||||
|
|
||||||
if ($identifiers) {
|
if ($identifiers) {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
|
Loading…
Reference in a new issue