From 409f2f4dd2888f88df2293466c37c768b94068e5 Mon Sep 17 00:00:00 2001 From: Drew Blessing Date: Wed, 17 Oct 2018 20:03:15 -0400 Subject: Improve performance of tree rendering in repositories with lots of items Rails is slow to generate paths dynamically especially when called hundreds/thousands of times. Also, rendering many partials hundreds of times can be slower. This change reduces the number of partials rendered and introduces two fast path methods to speed up path generation. --- .../projects/tree/_blob_item.html.haml_spec.rb | 40 ---------------------- .../projects/tree/_tree_row.html.haml_spec.rb | 37 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 spec/views/projects/tree/_blob_item.html.haml_spec.rb create mode 100644 spec/views/projects/tree/_tree_row.html.haml_spec.rb (limited to 'spec/views') diff --git a/spec/views/projects/tree/_blob_item.html.haml_spec.rb b/spec/views/projects/tree/_blob_item.html.haml_spec.rb deleted file mode 100644 index 6a477c712ff..00000000000 --- a/spec/views/projects/tree/_blob_item.html.haml_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe 'projects/tree/_blob_item' do - let(:project) { create(:project, :repository) } - let(:repository) { project.repository } - let(:blob_item) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files/ruby').first } - - before do - assign(:project, project) - assign(:repository, repository) - assign(:id, File.join('master', '')) - assign(:lfs_blob_ids, []) - end - - it 'renders blob item' do - render_partial(blob_item) - - expect(rendered).to have_content(blob_item.name) - expect(rendered).not_to have_selector('.label-lfs', text: 'LFS') - end - - describe 'LFS blob' do - before do - assign(:lfs_blob_ids, [blob_item].map(&:id)) - - render_partial(blob_item) - end - - it 'renders LFS badge' do - expect(rendered).to have_selector('.label-lfs', text: 'LFS') - end - end - - def render_partial(blob_item) - render partial: 'projects/tree/blob_item', locals: { - blob_item: blob_item, - type: 'blob' - } - end -end diff --git a/spec/views/projects/tree/_tree_row.html.haml_spec.rb b/spec/views/projects/tree/_tree_row.html.haml_spec.rb new file mode 100644 index 00000000000..3353b7665e2 --- /dev/null +++ b/spec/views/projects/tree/_tree_row.html.haml_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'projects/tree/_tree_row' do + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } + let(:blob_item) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files/ruby').first } + + before do + assign(:project, project) + assign(:repository, repository) + assign(:id, File.join('master', '')) + assign(:lfs_blob_ids, []) + end + + it 'renders blob item' do + render_partial(blob_item) + + expect(rendered).to have_content(blob_item.name) + expect(rendered).not_to have_selector('.label-lfs', text: 'LFS') + end + + describe 'LFS blob' do + before do + assign(:lfs_blob_ids, [blob_item].map(&:id)) + + render_partial(blob_item) + end + + it 'renders LFS badge' do + expect(rendered).to have_selector('.label-lfs', text: 'LFS') + end + end + + def render_partial(items) + render partial: 'projects/tree/tree_row', collection: [items].flatten + end +end -- cgit v1.2.1