diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-22 09:48:49 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-22 09:48:49 +0000 |
commit | 29b6d465a7491e9660c91e324df7a7b7d9d03868 (patch) | |
tree | 5abebae07d20871c8eacec306fc803be63c05d92 /spec/javascripts | |
parent | ea9dda9541caffe59714ff427918f674bec0a6f2 (diff) | |
parent | e17020b9079d6e4f349a1a01e5d43393b6b49f18 (diff) | |
download | gitlab-ce-29b6d465a7491e9660c91e324df7a7b7d9d03868.tar.gz |
Merge branch 'rs-dev-issue-2355' into 'master'
MergeRequest#show performance improvements
This is a first pass on improving the performance of the `MergeRequests#show` page. Notable changes:
- The "Commits" tab is loaded lazily, so the initial page load should be much faster for MRs with many commits.
- Relative timestamps via `timeago` are only initialized once per load instead of `O(n^2)`. This greatly improves frontend rendering times for a large number of commits.
- Refactored `User.find_for_commit` to use a single ARel-generated SQL query instead of the old method which resulted in one query, and could result in up to three.
See merge request !838
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/fixtures/merge_request_tabs.html.haml | 22 | ||||
-rw-r--r-- | spec/javascripts/merge_request_tabs_spec.js.coffee | 82 |
2 files changed, 104 insertions, 0 deletions
diff --git a/spec/javascripts/fixtures/merge_request_tabs.html.haml b/spec/javascripts/fixtures/merge_request_tabs.html.haml new file mode 100644 index 00000000000..7624a713948 --- /dev/null +++ b/spec/javascripts/fixtures/merge_request_tabs.html.haml @@ -0,0 +1,22 @@ +%ul.nav.nav-tabs.merge-request-tabs + %li.notes-tab + %a{href: '/foo/bar/merge_requests/1', data: {target: '#notes', action: 'notes', toggle: 'tab'}} + Discussion + %li.commits-tab + %a{href: '/foo/bar/merge_requests/1/commits', data: {target: '#commits', action: 'commits', toggle: 'tab'}} + Commits + %li.diffs-tab + %a{href: '/foo/bar/merge_requests/1/diffs', data: {target: '#diffs', action: 'diffs', toggle: 'tab'}} + Diffs + +.tab-content + #notes.notes.tab-pane + Notes Content + #commits.commits.tab-pane + Commits Content + #diffs.diffs.tab-pane + Diffs Content + +.mr-loading-status + .loading + Loading Animation diff --git a/spec/javascripts/merge_request_tabs_spec.js.coffee b/spec/javascripts/merge_request_tabs_spec.js.coffee new file mode 100644 index 00000000000..6cc96fb68a0 --- /dev/null +++ b/spec/javascripts/merge_request_tabs_spec.js.coffee @@ -0,0 +1,82 @@ +#= require merge_request_tabs + +describe 'MergeRequestTabs', -> + stubLocation = (stubs) -> + defaults = {pathname: '', search: '', hash: ''} + $.extend(defaults, stubs) + + fixture.preload('merge_request_tabs.html') + + beforeEach -> + @class = new MergeRequestTabs() + @spies = { + ajax: spyOn($, 'ajax').and.callFake -> + history: spyOn(history, 'replaceState').and.callFake -> + } + + describe '#activateTab', -> + beforeEach -> + fixture.load('merge_request_tabs.html') + @subject = @class.activateTab + + it 'shows the first tab when action is show', -> + @subject('show') + expect($('#notes')).toHaveClass('active') + + it 'shows the notes tab when action is notes', -> + @subject('notes') + expect($('#notes')).toHaveClass('active') + + it 'shows the commits tab when action is commits', -> + @subject('commits') + expect($('#commits')).toHaveClass('active') + + it 'shows the diffs tab when action is diffs', -> + @subject('diffs') + expect($('#diffs')).toHaveClass('active') + + describe '#setCurrentAction', -> + beforeEach -> + @subject = @class.setCurrentAction + + it 'changes from commits', -> + @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1/commits') + + expect(@subject('notes')).toBe('/foo/bar/merge_requests/1') + expect(@subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs') + + it 'changes from diffs', -> + @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1/diffs') + + expect(@subject('notes')).toBe('/foo/bar/merge_requests/1') + expect(@subject('commits')).toBe('/foo/bar/merge_requests/1/commits') + + it 'changes from notes', -> + @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1') + + expect(@subject('diffs')).toBe('/foo/bar/merge_requests/1/diffs') + expect(@subject('commits')).toBe('/foo/bar/merge_requests/1/commits') + + it 'includes search parameters and hash string', -> + @class._location = stubLocation({ + pathname: '/foo/bar/merge_requests/1/diffs' + search: '?view=parallel' + hash: '#L15-35' + }) + + expect(@subject('show')).toBe('/foo/bar/merge_requests/1?view=parallel#L15-35') + + it 'replaces the current history state', -> + @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1') + new_state = @subject('commits') + + expect(@spies.history).toHaveBeenCalledWith( + {turbolinks: true, url: new_state}, + document.title, + new_state + ) + + it 'treats "show" like "notes"', -> + @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1/commits') + + expect(@subject('show')).toBe('/foo/bar/merge_requests/1') |