Commit 66ea7846 authored by Robert May's avatar Robert May

Memoize the fork suggestion button partial

parent ca6cef2e
......@@ -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)
......
......@@ -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
......@@ -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