1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Batch all supplementary information in Diffusion browse views

Summary: Ref T2683. Instead of sending one request for each path's history, send one request for all of it. This permits optimizations which are not currently available to us. It degrades the user experience a tiny bit in theory, but on my machine it's actually way faster already.

Test Plan: Loaded a browse page.

Reviewers: vrana, btrahan

Reviewed By: btrahan

Subscribers: epriestley, aran

Maniphest Tasks: T2683

Differential Revision: https://secure.phabricator.com/D5254
This commit is contained in:
epriestley 2014-05-10 15:32:53 -07:00
parent ac020bc420
commit df59f4b047
3 changed files with 58 additions and 52 deletions

View file

@ -9,47 +9,50 @@ final class DiffusionLastModifiedController extends DiffusionController {
public function processRequest() { public function processRequest() {
$drequest = $this->getDiffusionRequest(); $drequest = $this->getDiffusionRequest();
$request = $this->getRequest(); $request = $this->getRequest();
$commit = null;
$commit_data = null;
$conduit_result = $this->callConduitWithDiffusionRequest( $paths = $request->getStr('paths');
'diffusion.lastmodifiedquery', $paths = json_decode($paths, true);
array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath()
));
$c_dict = $conduit_result['commit'];
if ($c_dict) {
$commit = PhabricatorRepositoryCommit::newFromDictionary($c_dict);
}
$c_d_dict = $conduit_result['commitData'];
if ($c_d_dict) {
$commit_data =
PhabricatorRepositoryCommitData::newFromDictionary($c_d_dict);
}
$phids = array(); $output = array();
if ($commit_data) { foreach ($paths as $path) {
if ($commit_data->getCommitDetail('authorPHID')) { $prequest = clone $drequest;
$phids[$commit_data->getCommitDetail('authorPHID')] = true; $prequest->setPath($path);
}
if ($commit_data->getCommitDetail('committerPHID')) { $conduit_result = $this->callConduitWithDiffusionRequest(
$phids[$commit_data->getCommitDetail('committerPHID')] = true; 'diffusion.lastmodifiedquery',
array(
'commit' => $prequest->getCommit(),
'path' => $prequest->getPath(),
));
$commit = PhabricatorRepositoryCommit::newFromDictionary(
$conduit_result['commit']);
$commit_data = PhabricatorRepositoryCommitData::newFromDictionary(
$conduit_result['commitData']);
$phids = array();
if ($commit_data) {
if ($commit_data->getCommitDetail('authorPHID')) {
$phids[$commit_data->getCommitDetail('authorPHID')] = true;
}
if ($commit_data->getCommitDetail('committerPHID')) {
$phids[$commit_data->getCommitDetail('committerPHID')] = true;
}
} }
$phids = array_keys($phids);
$handles = $this->loadViewerHandles($phids);
$view = new DiffusionBrowseTableView();
$view->setUser($request->getUser());
$output[$path] = $view->renderLastModifiedColumns(
$prequest,
$handles,
$commit,
$commit_data);
} }
$phids = array_keys($phids); return id(new AphrontAjaxResponse())->setContent($output);
$handles = $this->loadViewerHandles($phids);
$view = new DiffusionBrowseTableView();
$view->setUser($request->getUser());
$output = $view->renderLastModifiedColumns(
$drequest,
$handles,
$commit,
$commit_data);
return id(new AphrontAjaxResponse())
->setContent($output);
} }
} }

View file

@ -171,13 +171,7 @@ final class DiffusionBrowseTableView extends DiffusionView {
'details' => celerity_generate_unique_node_id(), 'details' => celerity_generate_unique_node_id(),
); );
$uri = (string)$request->generateURI( $need_pull[$base_path.$path->getPath().$dir_slash] = $dict;
array(
'action' => 'lastmodified',
'path' => $base_path.$path->getPath().$dir_slash,
));
$need_pull[$uri] = $dict;
foreach ($dict as $k => $uniq) { foreach ($dict as $k => $uniq) {
$dict[$k] = phutil_tag('span', array('id' => $uniq), ''); $dict[$k] = phutil_tag('span', array('id' => $uniq), '');
} }
@ -214,7 +208,15 @@ final class DiffusionBrowseTableView extends DiffusionView {
} }
if ($need_pull) { if ($need_pull) {
Javelin::initBehavior('diffusion-pull-lastmodified', $need_pull); Javelin::initBehavior(
'diffusion-pull-lastmodified',
array(
'uri' => (string)$request->generateURI(
array(
'action' => 'lastmodified',
)),
'map' => $need_pull,
));
} }
$branch = $this->getDiffusionRequest()->loadBranch(); $branch = $this->getDiffusionRequest()->loadBranch();

View file

@ -3,19 +3,20 @@
* @requires javelin-behavior * @requires javelin-behavior
* javelin-dom * javelin-dom
* javelin-util * javelin-util
* javelin-request * javelin-workflow
* javelin-json
*/ */
JX.behavior('diffusion-pull-lastmodified', function(config) { JX.behavior('diffusion-pull-lastmodified', function(config) {
for (var uri in config) { new JX.Workflow(config.uri, {paths: JX.JSON.stringify(JX.keys(config.map))})
new JX.Request(uri, JX.bind(config[uri], function(r) { .setHandler(function(r) {
for (var k in r) { for (var k in r) {
if (this[k]) { for (var l in r[k]) {
JX.DOM.setContent(JX.$(this[k]), JX.$H(r[k])); JX.DOM.setContent(JX.$(config.map[k][l]), JX.$H(r[k][l]));
} }
} }
})).send(); })
} .start();
}); });