From 606ef34d610dbe326e13ddd6e5dcf5b2e27a9da0 Mon Sep 17 00:00:00 2001 From: vrana Date: Tue, 31 Jul 2012 16:27:48 -0700 Subject: [PATCH] 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 --- src/__celerity_resource_map__.php | 13 +++ src/__phutil_library_map__.php | 4 + ...AphrontDefaultApplicationConfiguration.php | 5 ++ .../DiffusionCommitBranchesController.php | 48 ++++++++++ .../controller/DiffusionCommitController.php | 89 +++---------------- .../DiffusionCommitTagsController.php | 65 ++++++++++++++ .../diffusion/behavior-commit-branches.js | 19 ++++ 7 files changed, 164 insertions(+), 79 deletions(-) create mode 100644 src/applications/diffusion/controller/DiffusionCommitBranchesController.php create mode 100644 src/applications/diffusion/controller/DiffusionCommitTagsController.php create mode 100644 webroot/rsrc/js/application/diffusion/behavior-commit-branches.js diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 06ba1f2acd..72a9301782 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -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', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2b4101d396..1531fb874e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php index 9be1048237..f4a931223d 100644 --- a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php @@ -256,6 +256,11 @@ class AphrontDefaultApplicationConfiguration 'diff/' => 'DiffusionDiffController', 'tags/(?P.*)' => 'DiffusionTagListController', 'branches/(?P.*)' => 'DiffusionBranchTableController', + + 'commit/(?P[a-z0-9]+)/branches/' + => 'DiffusionCommitBranchesController', + 'commit/(?P[a-z0-9]+)/tags/' + => 'DiffusionCommitTagsController', ), 'inline/' => array( 'edit/(?P[^/]+)/' => 'DiffusionInlineCommentController', diff --git a/src/applications/diffusion/controller/DiffusionCommitBranchesController.php b/src/applications/diffusion/controller/DiffusionCommitBranchesController.php new file mode 100644 index 0000000000..28a3844749 --- /dev/null +++ b/src/applications/diffusion/controller/DiffusionCommitBranchesController.php @@ -0,0 +1,48 @@ +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'); + } +} diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index f5e15e5239..a6322e261f 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -383,15 +383,17 @@ final class DiffusionCommitController extends DiffusionController { $request = $this->getDiffusionRequest(); - $branches = $this->buildBranches($request); - if ($branches) { - $props['Branches'] = $branches; - } + $props['Branches'] = 'Unknown'; + $props['Tags'] = 'Unknown'; - $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. diff --git a/src/applications/diffusion/controller/DiffusionCommitTagsController.php b/src/applications/diffusion/controller/DiffusionCommitTagsController.php new file mode 100644 index 0000000000..14747f927f --- /dev/null +++ b/src/applications/diffusion/controller/DiffusionCommitTagsController.php @@ -0,0 +1,65 @@ +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'); + } +} diff --git a/webroot/rsrc/js/application/diffusion/behavior-commit-branches.js b/webroot/rsrc/js/application/diffusion/behavior-commit-branches.js new file mode 100644 index 0000000000..d72b5206f7 --- /dev/null +++ b/webroot/rsrc/js/application/diffusion/behavior-commit-branches.js @@ -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(); + } + +}); +