1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-29 16:08:22 +01:00

Load commit branches and tags by AJAX

Summary:
Each query takes over 2 seconds in FBCODE.
I didn't find a way how to speed them up.
There's also no easy way how to parallelize them at least.
So AJAX is the last instance.

Test Plan: Loaded commit with one branch and no tag.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3112
This commit is contained in:
vrana 2012-07-31 16:27:48 -07:00
parent d2031d3296
commit 606ef34d61
7 changed files with 164 additions and 79 deletions

View file

@ -1137,6 +1137,19 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/differential/behavior-user-select.js',
),
'javelin-behavior-diffusion-commit-branches' =>
array(
'uri' => '/res/e6ae17a6/rsrc/js/application/diffusion/behavior-commit-branches.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
2 => 'javelin-util',
3 => 'javelin-request',
),
'disk' => '/rsrc/js/application/diffusion/behavior-commit-branches.js',
),
'javelin-behavior-diffusion-commit-graph' =>
array(
'uri' => '/res/cfe336e8/rsrc/js/application/diffusion/behavior-commit-graph.js',

View file

@ -311,9 +311,11 @@ phutil_register_library_map(array(
'DiffusionChangeController' => 'applications/diffusion/controller/DiffusionChangeController.php',
'DiffusionCommentListView' => 'applications/diffusion/view/DiffusionCommentListView.php',
'DiffusionCommentView' => 'applications/diffusion/view/DiffusionCommentView.php',
'DiffusionCommitBranchesController' => 'applications/diffusion/controller/DiffusionCommitBranchesController.php',
'DiffusionCommitChangeTableView' => 'applications/diffusion/view/DiffusionCommitChangeTableView.php',
'DiffusionCommitController' => 'applications/diffusion/controller/DiffusionCommitController.php',
'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php',
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
'DiffusionCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionCommitTagsQuery.php',
'DiffusionContainsQuery' => 'applications/diffusion/query/contains/DiffusionContainsQuery.php',
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
@ -1402,9 +1404,11 @@ phutil_register_library_map(array(
'DiffusionChangeController' => 'DiffusionController',
'DiffusionCommentListView' => 'AphrontView',
'DiffusionCommentView' => 'AphrontView',
'DiffusionCommitBranchesController' => 'DiffusionController',
'DiffusionCommitChangeTableView' => 'DiffusionView',
'DiffusionCommitController' => 'DiffusionController',
'DiffusionCommitParentsQuery' => 'DiffusionQuery',
'DiffusionCommitTagsController' => 'DiffusionController',
'DiffusionCommitTagsQuery' => 'DiffusionQuery',
'DiffusionContainsQuery' => 'DiffusionQuery',
'DiffusionController' => 'PhabricatorController',

View file

@ -256,6 +256,11 @@ class AphrontDefaultApplicationConfiguration
'diff/' => 'DiffusionDiffController',
'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
'commit/(?P<commit>[a-z0-9]+)/branches/'
=> 'DiffusionCommitBranchesController',
'commit/(?P<commit>[a-z0-9]+)/tags/'
=> 'DiffusionCommitTagsController',
),
'inline/' => array(
'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',

View file

@ -0,0 +1,48 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionCommitBranchesController extends DiffusionController {
public function willProcessRequest(array $data) {
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
}
public function processRequest() {
$request = $this->getDiffusionRequest();
$branch_query = DiffusionContainsQuery::newFromDiffusionRequest($request);
$branches = $branch_query->loadContainingBranches();
$branch_links = array();
foreach ($branches as $branch => $commit) {
$branch_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'browse',
'branch' => $branch,
)),
),
phutil_escape_html($branch));
}
return id(new AphrontAjaxResponse())
->setContent($branch_links ? implode(', ', $branch_links) : 'None');
}
}

View file

@ -383,15 +383,17 @@ final class DiffusionCommitController extends DiffusionController {
$request = $this->getDiffusionRequest();
$branches = $this->buildBranches($request);
if ($branches) {
$props['Branches'] = $branches;
}
$props['Branches'] = '<span id="commit-branches">Unknown</span>';
$props['Tags'] = '<span id="commit-tags">Unknown</span>';
$tags = $this->buildTags($request);
if ($tags) {
$props['Tags'] = $tags;
}
$callsign = $request->getRepository()->getCallsign();
$root = '/diffusion/'.$callsign.'/commit/'.$commit->getCommitIdentifier();
Javelin::initBehavior(
'diffusion-commit-branches',
array(
$root.'/branches/' => 'commit-branches',
$root.'/tags/' => 'commit-tags',
));
$refs = $this->buildRefs($request);
if ($refs) {
@ -787,77 +789,6 @@ final class DiffusionCommitController extends DiffusionController {
return $action_list;
}
private function buildBranches(DiffusionRequest $request) {
$branch_query = DiffusionContainsQuery::newFromDiffusionRequest($request);
$branches = $branch_query->loadContainingBranches();
if (!$branches) {
return null;
}
$branch_links = array();
foreach ($branches as $branch => $commit) {
$branch_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'browse',
'branch' => $branch,
)),
),
phutil_escape_html($branch));
}
$branch_links = implode(', ', $branch_links);
return $branch_links;
}
private function buildTags(DiffusionRequest $request) {
$tag_limit = 10;
$tag_query = DiffusionCommitTagsQuery::newFromDiffusionRequest($request);
$tag_query->setLimit($tag_limit + 1);
$tags = $tag_query->loadTags();
if (!$tags) {
return null;
}
$has_more_tags = (count($tags) > $tag_limit);
$tags = array_slice($tags, 0, $tag_limit);
$tag_links = array();
foreach ($tags as $tag) {
$tag_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'browse',
'commit' => $tag->getName(),
)),
),
phutil_escape_html($tag->getName()));
}
if ($has_more_tags) {
$tag_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'tags',
)),
),
"More tags\xE2\x80\xA6");
}
$tag_links = implode(', ', $tag_links);
return $tag_links;
}
private function buildRefs(DiffusionRequest $request) {
// Not turning this into a proper Query class since it's pretty simple,
// one-off, and Git-specific.

View file

@ -0,0 +1,65 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionCommitTagsController extends DiffusionController {
public function willProcessRequest(array $data) {
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
}
public function processRequest() {
$request = $this->getDiffusionRequest();
$tag_limit = 10;
$tag_query = DiffusionCommitTagsQuery::newFromDiffusionRequest($request);
$tag_query->setLimit($tag_limit + 1);
$tags = $tag_query->loadTags();
$has_more_tags = (count($tags) > $tag_limit);
$tags = array_slice($tags, 0, $tag_limit);
$tag_links = array();
foreach ($tags as $tag) {
$tag_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'browse',
'commit' => $tag->getName(),
)),
),
phutil_escape_html($tag->getName()));
}
if ($has_more_tags) {
$tag_links[] = phutil_render_tag(
'a',
array(
'href' => $request->generateURI(
array(
'action' => 'tags',
)),
),
"More tags\xE2\x80\xA6");
}
return id(new AphrontAjaxResponse())
->setContent($tag_links ? implode(', ', $tag_links) : 'None');
}
}

View file

@ -0,0 +1,19 @@
/**
* @provides javelin-behavior-diffusion-commit-branches
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-request
*/
JX.behavior('diffusion-commit-branches', function(config) {
for (var uri in config) {
JX.DOM.setContent(JX.$(config[uri]), 'Loading...');
new JX.Request(uri, JX.bind(config[uri], function(r) {
JX.DOM.setContent(JX.$(this), JX.$H(r));
})).send();
}
});