@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

vrana 606ef34d d2031d32

+164 -79
+13
src/__celerity_resource_map__.php
··· 1137 1137 ), 1138 1138 'disk' => '/rsrc/js/application/differential/behavior-user-select.js', 1139 1139 ), 1140 + 'javelin-behavior-diffusion-commit-branches' => 1141 + array( 1142 + 'uri' => '/res/e6ae17a6/rsrc/js/application/diffusion/behavior-commit-branches.js', 1143 + 'type' => 'js', 1144 + 'requires' => 1145 + array( 1146 + 0 => 'javelin-behavior', 1147 + 1 => 'javelin-dom', 1148 + 2 => 'javelin-util', 1149 + 3 => 'javelin-request', 1150 + ), 1151 + 'disk' => '/rsrc/js/application/diffusion/behavior-commit-branches.js', 1152 + ), 1140 1153 'javelin-behavior-diffusion-commit-graph' => 1141 1154 array( 1142 1155 'uri' => '/res/cfe336e8/rsrc/js/application/diffusion/behavior-commit-graph.js',
+4
src/__phutil_library_map__.php
··· 311 311 'DiffusionChangeController' => 'applications/diffusion/controller/DiffusionChangeController.php', 312 312 'DiffusionCommentListView' => 'applications/diffusion/view/DiffusionCommentListView.php', 313 313 'DiffusionCommentView' => 'applications/diffusion/view/DiffusionCommentView.php', 314 + 'DiffusionCommitBranchesController' => 'applications/diffusion/controller/DiffusionCommitBranchesController.php', 314 315 'DiffusionCommitChangeTableView' => 'applications/diffusion/view/DiffusionCommitChangeTableView.php', 315 316 'DiffusionCommitController' => 'applications/diffusion/controller/DiffusionCommitController.php', 316 317 'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php', 318 + 'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php', 317 319 'DiffusionCommitTagsQuery' => 'applications/diffusion/query/committags/DiffusionCommitTagsQuery.php', 318 320 'DiffusionContainsQuery' => 'applications/diffusion/query/contains/DiffusionContainsQuery.php', 319 321 'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php', ··· 1402 1404 'DiffusionChangeController' => 'DiffusionController', 1403 1405 'DiffusionCommentListView' => 'AphrontView', 1404 1406 'DiffusionCommentView' => 'AphrontView', 1407 + 'DiffusionCommitBranchesController' => 'DiffusionController', 1405 1408 'DiffusionCommitChangeTableView' => 'DiffusionView', 1406 1409 'DiffusionCommitController' => 'DiffusionController', 1407 1410 'DiffusionCommitParentsQuery' => 'DiffusionQuery', 1411 + 'DiffusionCommitTagsController' => 'DiffusionController', 1408 1412 'DiffusionCommitTagsQuery' => 'DiffusionQuery', 1409 1413 'DiffusionContainsQuery' => 'DiffusionQuery', 1410 1414 'DiffusionController' => 'PhabricatorController',
+5
src/aphront/configuration/AphrontDefaultApplicationConfiguration.php
··· 256 256 'diff/' => 'DiffusionDiffController', 257 257 'tags/(?P<dblob>.*)' => 'DiffusionTagListController', 258 258 'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController', 259 + 260 + 'commit/(?P<commit>[a-z0-9]+)/branches/' 261 + => 'DiffusionCommitBranchesController', 262 + 'commit/(?P<commit>[a-z0-9]+)/tags/' 263 + => 'DiffusionCommitTagsController', 259 264 ), 260 265 'inline/' => array( 261 266 'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
+48
src/applications/diffusion/controller/DiffusionCommitBranchesController.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class DiffusionCommitBranchesController extends DiffusionController { 20 + 21 + public function willProcessRequest(array $data) { 22 + $this->diffusionRequest = DiffusionRequest::newFromDictionary($data); 23 + } 24 + 25 + public function processRequest() { 26 + $request = $this->getDiffusionRequest(); 27 + 28 + $branch_query = DiffusionContainsQuery::newFromDiffusionRequest($request); 29 + $branches = $branch_query->loadContainingBranches(); 30 + 31 + $branch_links = array(); 32 + foreach ($branches as $branch => $commit) { 33 + $branch_links[] = phutil_render_tag( 34 + 'a', 35 + array( 36 + 'href' => $request->generateURI( 37 + array( 38 + 'action' => 'browse', 39 + 'branch' => $branch, 40 + )), 41 + ), 42 + phutil_escape_html($branch)); 43 + } 44 + 45 + return id(new AphrontAjaxResponse()) 46 + ->setContent($branch_links ? implode(', ', $branch_links) : 'None'); 47 + } 48 + }
+10 -79
src/applications/diffusion/controller/DiffusionCommitController.php
··· 383 383 384 384 $request = $this->getDiffusionRequest(); 385 385 386 - $branches = $this->buildBranches($request); 387 - if ($branches) { 388 - $props['Branches'] = $branches; 389 - } 386 + $props['Branches'] = '<span id="commit-branches">Unknown</span>'; 387 + $props['Tags'] = '<span id="commit-tags">Unknown</span>'; 390 388 391 - $tags = $this->buildTags($request); 392 - if ($tags) { 393 - $props['Tags'] = $tags; 394 - } 389 + $callsign = $request->getRepository()->getCallsign(); 390 + $root = '/diffusion/'.$callsign.'/commit/'.$commit->getCommitIdentifier(); 391 + Javelin::initBehavior( 392 + 'diffusion-commit-branches', 393 + array( 394 + $root.'/branches/' => 'commit-branches', 395 + $root.'/tags/' => 'commit-tags', 396 + )); 395 397 396 398 $refs = $this->buildRefs($request); 397 399 if ($refs) { ··· 785 787 $action_list->setActions($actions); 786 788 787 789 return $action_list; 788 - } 789 - 790 - private function buildBranches(DiffusionRequest $request) { 791 - 792 - $branch_query = DiffusionContainsQuery::newFromDiffusionRequest($request); 793 - $branches = $branch_query->loadContainingBranches(); 794 - 795 - if (!$branches) { 796 - return null; 797 - } 798 - 799 - $branch_links = array(); 800 - foreach ($branches as $branch => $commit) { 801 - $branch_links[] = phutil_render_tag( 802 - 'a', 803 - array( 804 - 'href' => $request->generateURI( 805 - array( 806 - 'action' => 'browse', 807 - 'branch' => $branch, 808 - )), 809 - ), 810 - phutil_escape_html($branch)); 811 - } 812 - $branch_links = implode(', ', $branch_links); 813 - return $branch_links; 814 - } 815 - 816 - private function buildTags(DiffusionRequest $request) { 817 - $tag_limit = 10; 818 - 819 - $tag_query = DiffusionCommitTagsQuery::newFromDiffusionRequest($request); 820 - $tag_query->setLimit($tag_limit + 1); 821 - $tags = $tag_query->loadTags(); 822 - 823 - if (!$tags) { 824 - return null; 825 - } 826 - 827 - $has_more_tags = (count($tags) > $tag_limit); 828 - $tags = array_slice($tags, 0, $tag_limit); 829 - 830 - $tag_links = array(); 831 - foreach ($tags as $tag) { 832 - $tag_links[] = phutil_render_tag( 833 - 'a', 834 - array( 835 - 'href' => $request->generateURI( 836 - array( 837 - 'action' => 'browse', 838 - 'commit' => $tag->getName(), 839 - )), 840 - ), 841 - phutil_escape_html($tag->getName())); 842 - } 843 - 844 - if ($has_more_tags) { 845 - $tag_links[] = phutil_render_tag( 846 - 'a', 847 - array( 848 - 'href' => $request->generateURI( 849 - array( 850 - 'action' => 'tags', 851 - )), 852 - ), 853 - "More tags\xE2\x80\xA6"); 854 - } 855 - 856 - $tag_links = implode(', ', $tag_links); 857 - 858 - return $tag_links; 859 790 } 860 791 861 792 private function buildRefs(DiffusionRequest $request) {
+65
src/applications/diffusion/controller/DiffusionCommitTagsController.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class DiffusionCommitTagsController extends DiffusionController { 20 + 21 + public function willProcessRequest(array $data) { 22 + $this->diffusionRequest = DiffusionRequest::newFromDictionary($data); 23 + } 24 + 25 + public function processRequest() { 26 + $request = $this->getDiffusionRequest(); 27 + $tag_limit = 10; 28 + 29 + $tag_query = DiffusionCommitTagsQuery::newFromDiffusionRequest($request); 30 + $tag_query->setLimit($tag_limit + 1); 31 + $tags = $tag_query->loadTags(); 32 + 33 + $has_more_tags = (count($tags) > $tag_limit); 34 + $tags = array_slice($tags, 0, $tag_limit); 35 + 36 + $tag_links = array(); 37 + foreach ($tags as $tag) { 38 + $tag_links[] = phutil_render_tag( 39 + 'a', 40 + array( 41 + 'href' => $request->generateURI( 42 + array( 43 + 'action' => 'browse', 44 + 'commit' => $tag->getName(), 45 + )), 46 + ), 47 + phutil_escape_html($tag->getName())); 48 + } 49 + 50 + if ($has_more_tags) { 51 + $tag_links[] = phutil_render_tag( 52 + 'a', 53 + array( 54 + 'href' => $request->generateURI( 55 + array( 56 + 'action' => 'tags', 57 + )), 58 + ), 59 + "More tags\xE2\x80\xA6"); 60 + } 61 + 62 + return id(new AphrontAjaxResponse()) 63 + ->setContent($tag_links ? implode(', ', $tag_links) : 'None'); 64 + } 65 + }
+19
webroot/rsrc/js/application/diffusion/behavior-commit-branches.js
··· 1 + /** 2 + * @provides javelin-behavior-diffusion-commit-branches 3 + * @requires javelin-behavior 4 + * javelin-dom 5 + * javelin-util 6 + * javelin-request 7 + */ 8 + 9 + JX.behavior('diffusion-commit-branches', function(config) { 10 + 11 + for (var uri in config) { 12 + JX.DOM.setContent(JX.$(config[uri]), 'Loading...'); 13 + new JX.Request(uri, JX.bind(config[uri], function(r) { 14 + JX.DOM.setContent(JX.$(this), JX.$H(r)); 15 + })).send(); 16 + } 17 + 18 + }); 19 +