Commit ad2a750e authored by Sean McGivern's avatar Sean McGivern

Merge branch 'id-pass-blob-to-webide-buttons' into 'master'

Pass blob to webide-buttons for reducing number of Gitaly requests

See merge request gitlab-org/gitlab!49411
parents 465071d0 87c6402a
...@@ -328,8 +328,9 @@ module BlobHelper ...@@ -328,8 +328,9 @@ module BlobHelper
end end
def readable_blob(options, path, project, ref) def readable_blob(options, path, project, ref)
blob = options.delete(:blob) blob = options.fetch(:blob) do
blob ||= project.repository.blob_at(ref, path) rescue nil project.repository.blob_at(ref, path) rescue nil
end
blob if blob&.readable_text? blob if blob&.readable_text?
end end
......
...@@ -228,12 +228,12 @@ module TreeHelper ...@@ -228,12 +228,12 @@ module TreeHelper
gitpod_enabled: !current_user.nil? && current_user.gitpod_enabled, gitpod_enabled: !current_user.nil? && current_user.gitpod_enabled,
is_blob: !options[:blob].nil?, 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_web_ide_button: show_web_ide_button?,
show_gitpod_button: show_gitpod_button?, show_gitpod_button: show_gitpod_button?,
web_ide_url: web_ide_url, web_ide_url: web_ide_url,
edit_url: edit_url, edit_url: edit_url(options),
gitpod_url: gitpod_url gitpod_url: gitpod_url
} }
end end
......
...@@ -21,8 +21,8 @@ module WebIdeButtonHelper ...@@ -21,8 +21,8 @@ module WebIdeButtonHelper
can_collaborate? || can_create_mr_from_fork? can_collaborate? || can_create_mr_from_fork?
end end
def show_edit_button? def show_edit_button?(options = {})
readable_blob? && show_web_ide_button? readable_blob?(options) && show_web_ide_button?
end end
def show_gitpod_button? def show_gitpod_button?
...@@ -37,8 +37,8 @@ module WebIdeButtonHelper ...@@ -37,8 +37,8 @@ module WebIdeButtonHelper
!project_fork.nil? && !can_push_code? !project_fork.nil? && !can_push_code?
end end
def readable_blob? def readable_blob?(options = {})
!readable_blob({}, @path, @project, @ref).nil? !readable_blob(options, @path, @project, @ref).nil?
end end
def needs_to_fork? def needs_to_fork?
...@@ -49,8 +49,8 @@ module WebIdeButtonHelper ...@@ -49,8 +49,8 @@ module WebIdeButtonHelper
ide_edit_path(project_to_use, @ref, @path || '') ide_edit_path(project_to_use, @ref, @path || '')
end end
def edit_url def edit_url(options = {})
readable_blob? ? edit_blob_path(@project, @ref, @path || '') : '' readable_blob?(options) ? edit_blob_path(@project, @ref, @path || '') : ''
end end
def gitpod_url def gitpod_url
......
- type = blob ? 'blob' : 'tree' - 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' = render 'shared/confirm_fork_modal', fork_path: fork_and_edit_path(@project, @ref, @path), type: 'edit'
- if show_web_ide_button? - if show_web_ide_button?
= render 'shared/confirm_fork_modal', fork_path: ide_fork_and_edit_path(@project, @ref, @path), type: 'webide' = 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 ...@@ -216,6 +216,24 @@ RSpec.describe TreeHelper do
web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}/-/#{@path}" web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}/-/#{@path}"
) )
end 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 end
context 'user does not have write access but a personal fork exists' do 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