Skip to content

Commit e57f209

Browse files
author
vrana
committed
Load blame in Diffusion by AJAX
Summary: I have blame enabled by default and displaying files with long history takes easily over 10 seconds. Load the blame data by AJAX instead. This is actually doing more work and the total response time is longer but it's worth it for me as I am interested just in the file contents quite often. I know you were talking about building blame cache but until we have it... I'm not sure if the AJAX loading indicator in bottom right corner is enough to inform the user that we are loading it on background. Test Plan: ?view=highlighted ?view=plainblame ?view=blame Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5244
1 parent b0e58fa commit e57f209

File tree

5 files changed

+102
-46
lines changed

5 files changed

+102
-46
lines changed

scripts/celerity_mapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'javelin-behavior-aphront-drag-and-drop-textarea',
137137
'javelin-behavior-phabricator-object-selector',
138138
'javelin-behavior-repository-crossreference',
139+
'javelin-behavior-load-blame',
139140

140141
'differential-inline-comment-editor',
141142
'javelin-behavior-differential-dropdown-menus',

src/__celerity_resource_map__.php

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@
928928
),
929929
'diffusion-source-css' =>
930930
array(
931-
'uri' => '/res/6a28b429/rsrc/css/application/diffusion/diffusion-source.css',
931+
'uri' => '/res/e76bcd50/rsrc/css/application/diffusion/diffusion-source.css',
932932
'type' => 'css',
933933
'requires' =>
934934
array(
@@ -1582,6 +1582,18 @@
15821582
),
15831583
'disk' => '/rsrc/js/application/maniphest/behavior-line-chart.js',
15841584
),
1585+
'javelin-behavior-load-blame' =>
1586+
array(
1587+
'uri' => '/res/138e2961/rsrc/js/application/diffusion/behavior-load-blame.js',
1588+
'type' => 'js',
1589+
'requires' =>
1590+
array(
1591+
0 => 'javelin-behavior',
1592+
1 => 'javelin-dom',
1593+
2 => 'javelin-request',
1594+
),
1595+
'disk' => '/rsrc/js/application/diffusion/behavior-load-blame.js',
1596+
),
15851597
'javelin-behavior-maniphest-batch-editor' =>
15861598
array(
15871599
'uri' => '/res/d22661be/rsrc/js/application/maniphest/behavior-batch-editor.js',
@@ -3601,7 +3613,7 @@
36013613
'uri' => '/res/pkg/8aaacd1b/differential.pkg.css',
36023614
'type' => 'css',
36033615
),
3604-
'd2447f72' =>
3616+
'322728f3' =>
36053617
array(
36063618
'name' => 'differential.pkg.js',
36073619
'symbols' =>
@@ -3621,12 +3633,13 @@
36213633
12 => 'javelin-behavior-aphront-drag-and-drop-textarea',
36223634
13 => 'javelin-behavior-phabricator-object-selector',
36233635
14 => 'javelin-behavior-repository-crossreference',
3624-
15 => 'differential-inline-comment-editor',
3625-
16 => 'javelin-behavior-differential-dropdown-menus',
3626-
17 => 'javelin-behavior-differential-toggle-files',
3627-
18 => 'javelin-behavior-differential-user-select',
3636+
15 => 'javelin-behavior-load-blame',
3637+
16 => 'differential-inline-comment-editor',
3638+
17 => 'javelin-behavior-differential-dropdown-menus',
3639+
18 => 'javelin-behavior-differential-toggle-files',
3640+
19 => 'javelin-behavior-differential-user-select',
36283641
),
3629-
'uri' => '/res/pkg/d2447f72/differential.pkg.js',
3642+
'uri' => '/res/pkg/322728f3/differential.pkg.js',
36303643
'type' => 'js',
36313644
),
36323645
'c8ce2d88' =>
@@ -3724,7 +3737,7 @@
37243737
'aphront-typeahead-control-css' => '09aa1f68',
37253738
'differential-changeset-view-css' => '8aaacd1b',
37263739
'differential-core-view-css' => '8aaacd1b',
3727-
'differential-inline-comment-editor' => 'd2447f72',
3740+
'differential-inline-comment-editor' => '322728f3',
37283741
'differential-local-commits-view-css' => '8aaacd1b',
37293742
'differential-results-table-css' => '8aaacd1b',
37303743
'differential-revision-add-comment-css' => '8aaacd1b',
@@ -3742,31 +3755,32 @@
37423755
'javelin-behavior-aphlict-dropdown' => 'f24c209c',
37433756
'javelin-behavior-aphlict-listen' => 'f24c209c',
37443757
'javelin-behavior-aphront-basic-tokenizer' => 'f24c209c',
3745-
'javelin-behavior-aphront-drag-and-drop' => 'd2447f72',
3746-
'javelin-behavior-aphront-drag-and-drop-textarea' => 'd2447f72',
3758+
'javelin-behavior-aphront-drag-and-drop' => '322728f3',
3759+
'javelin-behavior-aphront-drag-and-drop-textarea' => '322728f3',
37473760
'javelin-behavior-aphront-form-disable-on-submit' => 'f24c209c',
37483761
'javelin-behavior-audit-preview' => 'f96657b8',
37493762
'javelin-behavior-dark-console' => 'dca4a03d',
37503763
'javelin-behavior-device' => 'f24c209c',
3751-
'javelin-behavior-differential-accept-with-errors' => 'd2447f72',
3752-
'javelin-behavior-differential-add-reviewers-and-ccs' => 'd2447f72',
3753-
'javelin-behavior-differential-comment-jump' => 'd2447f72',
3754-
'javelin-behavior-differential-diff-radios' => 'd2447f72',
3755-
'javelin-behavior-differential-dropdown-menus' => 'd2447f72',
3756-
'javelin-behavior-differential-edit-inline-comments' => 'd2447f72',
3757-
'javelin-behavior-differential-feedback-preview' => 'd2447f72',
3758-
'javelin-behavior-differential-keyboard-navigation' => 'd2447f72',
3759-
'javelin-behavior-differential-populate' => 'd2447f72',
3760-
'javelin-behavior-differential-show-more' => 'd2447f72',
3761-
'javelin-behavior-differential-toggle-files' => 'd2447f72',
3762-
'javelin-behavior-differential-user-select' => 'd2447f72',
3764+
'javelin-behavior-differential-accept-with-errors' => '322728f3',
3765+
'javelin-behavior-differential-add-reviewers-and-ccs' => '322728f3',
3766+
'javelin-behavior-differential-comment-jump' => '322728f3',
3767+
'javelin-behavior-differential-diff-radios' => '322728f3',
3768+
'javelin-behavior-differential-dropdown-menus' => '322728f3',
3769+
'javelin-behavior-differential-edit-inline-comments' => '322728f3',
3770+
'javelin-behavior-differential-feedback-preview' => '322728f3',
3771+
'javelin-behavior-differential-keyboard-navigation' => '322728f3',
3772+
'javelin-behavior-differential-populate' => '322728f3',
3773+
'javelin-behavior-differential-show-more' => '322728f3',
3774+
'javelin-behavior-differential-toggle-files' => '322728f3',
3775+
'javelin-behavior-differential-user-select' => '322728f3',
37633776
'javelin-behavior-diffusion-commit-graph' => 'f96657b8',
37643777
'javelin-behavior-diffusion-pull-lastmodified' => 'f96657b8',
37653778
'javelin-behavior-error-log' => 'dca4a03d',
37663779
'javelin-behavior-global-drag-and-drop' => 'f24c209c',
37673780
'javelin-behavior-history-install' => 'f24c209c',
37683781
'javelin-behavior-konami' => 'f24c209c',
37693782
'javelin-behavior-lightbox-attachments' => 'f24c209c',
3783+
'javelin-behavior-load-blame' => '322728f3',
37703784
'javelin-behavior-maniphest-batch-selector' => '7707de41',
37713785
'javelin-behavior-maniphest-subpriority-editor' => '7707de41',
37723786
'javelin-behavior-maniphest-transaction-controls' => '7707de41',
@@ -3776,15 +3790,15 @@
37763790
'javelin-behavior-phabricator-autofocus' => 'f24c209c',
37773791
'javelin-behavior-phabricator-keyboard-shortcuts' => 'f24c209c',
37783792
'javelin-behavior-phabricator-nav' => 'f24c209c',
3779-
'javelin-behavior-phabricator-object-selector' => 'd2447f72',
3793+
'javelin-behavior-phabricator-object-selector' => '322728f3',
37803794
'javelin-behavior-phabricator-oncopy' => 'f24c209c',
37813795
'javelin-behavior-phabricator-remarkup-assist' => 'f24c209c',
37823796
'javelin-behavior-phabricator-reveal-content' => 'f24c209c',
37833797
'javelin-behavior-phabricator-search-typeahead' => 'f24c209c',
37843798
'javelin-behavior-phabricator-tooltips' => 'f24c209c',
37853799
'javelin-behavior-phabricator-watch-anchor' => 'f24c209c',
37863800
'javelin-behavior-refresh-csrf' => 'f24c209c',
3787-
'javelin-behavior-repository-crossreference' => 'd2447f72',
3801+
'javelin-behavior-repository-crossreference' => '322728f3',
37883802
'javelin-behavior-toggle-class' => 'f24c209c',
37893803
'javelin-behavior-workflow' => 'f24c209c',
37903804
'javelin-dom' => 'cd1d650a',
@@ -3814,7 +3828,7 @@
38143828
'phabricator-core-css' => '09aa1f68',
38153829
'phabricator-crumbs-view-css' => '09aa1f68',
38163830
'phabricator-directory-css' => '09aa1f68',
3817-
'phabricator-drag-and-drop-file-upload' => 'd2447f72',
3831+
'phabricator-drag-and-drop-file-upload' => '322728f3',
38183832
'phabricator-dropdown-menu' => 'f24c209c',
38193833
'phabricator-file-upload' => 'f24c209c',
38203834
'phabricator-filetree-view-css' => '09aa1f68',
@@ -3836,7 +3850,7 @@
38363850
'phabricator-prefab' => 'f24c209c',
38373851
'phabricator-project-tag-css' => 'e30a3fa8',
38383852
'phabricator-remarkup-css' => '09aa1f68',
3839-
'phabricator-shaped-request' => 'd2447f72',
3853+
'phabricator-shaped-request' => '322728f3',
38403854
'phabricator-side-menu-view-css' => '09aa1f68',
38413855
'phabricator-standard-page-view' => '09aa1f68',
38423856
'phabricator-textareautils' => 'f24c209c',

src/applications/diffusion/controller/DiffusionBrowseFileController.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public function processRequest() {
3535
->setURI($request->getRequestURI()->alter('view', $selected));
3636
}
3737

38-
$needs_blame = ($selected == 'blame' || $selected == 'plainblame');
38+
$needs_blame = ($selected == 'plainblame');
39+
if ($selected == 'blame' && $request->isAjax()) {
40+
$needs_blame = true;
41+
}
3942

4043
$file_query = DiffusionFileContentQuery::newFromDiffusionRequest(
4144
$this->diffusionRequest);
@@ -59,6 +62,10 @@ public function processRequest() {
5962
$path,
6063
$data);
6164

65+
if ($request->isAjax()) {
66+
return id(new AphrontAjaxResponse())->setContent($corpus);
67+
}
68+
6269
require_celerity_resource('diffusion-source-css');
6370

6471
if ($this->corpusType == 'text') {
@@ -229,6 +236,18 @@ private function buildCorpus($selected,
229236
$rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict,
230237
$needs_blame, $drequest, $file_query, $selected);
231238

239+
$corpus_table = javelin_tag(
240+
'table',
241+
array(
242+
'class' => "diffusion-source remarkup-code PhabricatorMonospaced",
243+
'sigil' => 'diffusion-source',
244+
),
245+
$rows);
246+
247+
if ($this->getRequest()->isAjax()) {
248+
return $corpus_table;
249+
}
250+
232251
$id = celerity_generate_unique_node_id();
233252

234253
$projects = $drequest->loadArcanistProjects();
@@ -260,14 +279,6 @@ private function buildCorpus($selected,
260279
));
261280
}
262281

263-
$corpus_table = javelin_tag(
264-
'table',
265-
array(
266-
'class' => "diffusion-source remarkup-code PhabricatorMonospaced",
267-
'sigil' => 'diffusion-source',
268-
),
269-
$rows);
270-
271282
$corpus = phutil_tag(
272283
'div',
273284
array(
@@ -276,6 +287,8 @@ private function buildCorpus($selected,
276287
),
277288
$corpus_table);
278289

290+
Javelin::initBehavior('load-blame', array('id' => $id));
291+
279292
break;
280293
}
281294

@@ -449,7 +462,6 @@ private function buildDisplayRows(
449462
$color = null;
450463
foreach ($text_list as $k => $line) {
451464
$display_line = array(
452-
'color' => null,
453465
'epoch' => null,
454466
'commit' => null,
455467
'author' => null,
@@ -459,7 +471,7 @@ private function buildDisplayRows(
459471
'data' => $line,
460472
);
461473

462-
if ($needs_blame) {
474+
if ($selected == 'blame') {
463475
// If the line's rev is same as the line above, show empty content
464476
// with same color; otherwise generate blame info. The newer a change
465477
// is, the more saturated the color.
@@ -568,7 +580,7 @@ private function buildDisplayRows(
568580

569581
$rows = $this->renderInlines(
570582
idx($inlines, 0, array()),
571-
$needs_blame,
583+
($selected == 'blame'),
572584
$engine);
573585

574586
foreach ($display as $line) {
@@ -581,8 +593,11 @@ private function buildDisplayRows(
581593
));
582594

583595
$blame = array();
584-
if ($line['color']) {
585-
$color = $line['color'];
596+
$style = null;
597+
if (array_key_exists('color', $line)) {
598+
if ($line['color']) {
599+
$style = 'background: '.$line['color'].';';
600+
}
586601

587602
$before_link = null;
588603
$commit_link = null;
@@ -667,31 +682,31 @@ private function buildDisplayRows(
667682
'th',
668683
array(
669684
'class' => 'diffusion-blame-link',
670-
'style' => 'background: '.$color,
685+
'style' => $style,
671686
),
672687
$before_link);
673688

674689
$blame[] = phutil_tag(
675690
'th',
676691
array(
677692
'class' => 'diffusion-rev-link',
678-
'style' => 'background: '.$color,
693+
'style' => $style,
679694
),
680695
$commit_link);
681696

682697
$blame[] = phutil_tag(
683698
'th',
684699
array(
685700
'class' => 'diffusion-rev-link',
686-
'style' => 'background: '.$color,
701+
'style' => $style,
687702
),
688703
$revision_link);
689704

690705
$blame[] = phutil_tag(
691706
'th',
692707
array(
693708
'class' => 'diffusion-author-link',
694-
'style' => 'background: '.$color,
709+
'style' => $style,
695710
),
696711
idx($line, 'author'));
697712
}
@@ -708,7 +723,7 @@ private function buildDisplayRows(
708723
array(
709724
'class' => 'diffusion-line-link',
710725
'sigil' => 'diffusion-line-link',
711-
'style' => isset($color) ? 'background: '.$color : null,
726+
'style' => $style,
712727
),
713728
$line_link);
714729

@@ -753,7 +768,7 @@ private function buildDisplayRows(
753768

754769
$rows = array_merge($rows, $this->renderInlines(
755770
idx($inlines, $line['line'], array()),
756-
$needs_blame,
771+
($selected == 'blame'),
757772
$engine));
758773
}
759774

webroot/rsrc/css/application/diffusion/diffusion-source.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
white-space: nowrap;
4646
}
4747

48+
.diffusion-blame-link {
49+
min-width: 25px;
50+
}
51+
52+
.diffusion-rev-link {
53+
min-width: 90px;
54+
}
55+
56+
.diffusion-author-link {
57+
min-width: 120px;
58+
}
59+
4860
.diffusion-blame-link a,
4961
.diffusion-rev-link a,
5062
.diffusion-author-link a,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @provides javelin-behavior-load-blame
3+
* @requires javelin-behavior
4+
* javelin-dom
5+
* javelin-request
6+
*/
7+
8+
JX.behavior('load-blame', function(config) {
9+
10+
new JX.Request(location.href, function (response) {
11+
JX.DOM.setContent(JX.$(config.id), JX.$H(response));
12+
}).send();
13+
14+
});

0 commit comments

Comments
 (0)