Commit 87c6402a authored by Igor Drozdov's avatar Igor Drozdov

Pass blob to webide-buttons for optimizing

In this case we won't need to load the blob every time
parent 6e896a5f
......@@ -332,8 +332,9 @@ module BlobHelper
end
def readable_blob(options, path, project, ref)
blob = options.delete(:blob)
blob ||= project.repository.blob_at(ref, path) rescue nil
blob = options.fetch(:blob) do
project.repository.blob_at(ref, path) rescue nil
end
blob if blob&.readable_text?
end
......
......@@ -228,12 +228,12 @@ module TreeHelper
gitpod_enabled: !current_user.nil? && current_user.gitpod_enabled,
is_blob: !options[:blob].nil?,
show_edit_button: show_edit_button?,
show_edit_button: show_edit_button?(options),
show_web_ide_button: show_web_ide_button?,
show_gitpod_button: show_gitpod_button?,
web_ide_url: web_ide_url,
edit_url: edit_url,
edit_url: edit_url(options),
gitpod_url: gitpod_url
}
end
......
......@@ -21,8 +21,8 @@ module WebIdeButtonHelper
can_collaborate? || can_create_mr_from_fork?
end
def show_edit_button?
readable_blob? && show_web_ide_button?
def show_edit_button?(options = {})
readable_blob?(options) && show_web_ide_button?
end
def show_gitpod_button?
......@@ -37,8 +37,8 @@ module WebIdeButtonHelper
!project_fork.nil? && !can_push_code?
end
def readable_blob?
!readable_blob({}, @path, @project, @ref).nil?
def readable_blob?(options = {})
!readable_blob(options, @path, @project, @ref).nil?
end
def needs_to_fork?
......@@ -49,8 +49,8 @@ module WebIdeButtonHelper
ide_edit_path(project_to_use, @ref, @path || '')
end
def edit_url
readable_blob? ? edit_blob_path(@project, @ref, @path || '') : ''
def edit_url(options = {})
readable_blob?(options) ? edit_blob_path(@project, @ref, @path || '') : ''
end
def gitpod_url
......
- type = blob ? 'blob' : 'tree'
.d-inline-block{ data: { options: web_ide_button_data(blob: blob).to_json }, id: "js-#{type}-web-ide-link" }
.d-inline-block{ data: { options: web_ide_button_data({ blob: blob }).to_json }, id: "js-#{type}-web-ide-link" }
- if show_edit_button?
- if show_edit_button?({ blob: blob })
= render 'shared/confirm_fork_modal', fork_path: fork_and_edit_path(@project, @ref, @path), type: 'edit'
- if show_web_ide_button?
= render 'shared/confirm_fork_modal', fork_path: ide_fork_and_edit_path(@project, @ref, @path), type: 'webide'
......
......@@ -216,6 +216,24 @@ RSpec.describe TreeHelper do
web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}/-/#{@path}"
)
end
it 'does not load blob from repository again' do
blob
expect(repository).not_to receive(:blob_at)
subject
end
end
context 'nil blob is passed' do
let(:blob) { nil }
it 'does not load blob from repository' do
expect(repository).not_to receive(:blob_at)
subject
end
end
context 'user does not have write access but a personal fork exists' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment