Commit 25c1fcfc authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'memoize-fork-button' into 'master'

Memoize the fork suggestion button partial

See merge request gitlab-org/gitlab!53256
parents 83865fed 0263f9fa
......@@ -214,6 +214,15 @@ module DiffHelper
)
end
# As the fork suggestion button is identical every time, we cache it for a full page load
def render_fork_suggestion
return unless current_user
strong_memoize(:fork_suggestion) do
render partial: "projects/fork_suggestion"
end
end
private
def diff_btn(title, name, selected)
......
- if current_user
.js-file-fork-suggestion-section.file-fork-suggestion.hidden
%span.file-fork-suggestion-note
You're not allowed to
%span.js-file-fork-suggestion-section-action
edit
files in this project directly. Please fork this project,
make your changes there, and submit a merge request.
= link_to 'Fork', nil, method: :post, class: 'js-fork-suggestion-button gl-button btn btn-grouped btn-inverted btn-success'
%button.js-cancel-fork-suggestion-button.gl-button.btn.btn-grouped{ type: 'button' }
Cancel
.js-file-fork-suggestion-section.file-fork-suggestion.hidden
%span.file-fork-suggestion-note
You're not allowed to
%span.js-file-fork-suggestion-section-action
edit
files in this project directly. Please fork this project,
make your changes there, and submit a merge request.
= link_to 'Fork', nil, method: :post, class: 'js-fork-suggestion-button gl-button btn btn-grouped btn-inverted btn-success'
%button.js-cancel-fork-suggestion-button.gl-button.btn.btn-grouped{ type: 'button' }
Cancel
......@@ -20,5 +20,5 @@
= download_blob_button(blob)
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
= render 'projects/fork_suggestion'
= render_fork_suggestion
= render_if_exists 'projects/blob/header_file_locks', project: @project, path: @path
......@@ -30,6 +30,6 @@
= view_file_button(diff_file.content_sha, diff_file.file_path, project)
= view_on_environment_button(diff_file.content_sha, diff_file.file_path, environment) if environment
= render 'projects/fork_suggestion'
= render_fork_suggestion
= render 'projects/diffs/content', diff_file: diff_file
---
title: Memoize the fork suggestion button partial
merge_request: 53256
author:
type: performance
......@@ -378,4 +378,28 @@ RSpec.describe DiffHelper do
expect(subject).to match(/foo\/bar\/-\/commit\/#{commit.sha}\/diff_for_path/)
end
end
describe "#render_fork_suggestion" do
subject { helper.render_fork_suggestion }
before do
allow(helper).to receive(:current_user).and_return(current_user)
end
context "user signed in" do
let(:current_user) { build(:user) }
it "renders the partial" do
expect(helper).to receive(:render).with(partial: "projects/fork_suggestion").exactly(:once)
5.times { subject }
end
end
context "guest" do
let(:current_user) { nil }
it { is_expected.to be_nil }
end
end
end
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