Commit 833013ba authored by Thong Kuah's avatar Thong Kuah

Merge branch 'sh-strong-memoize-appearances' into 'master'

Memoize non-existent custom appearances

See merge request gitlab-org/gitlab-ce!29957
parents e740580d 5fbd0ff4
......@@ -2,6 +2,7 @@
module AppearancesHelper
include MarkupHelper
include Gitlab::Utils::StrongMemoize
def brand_title
current_appearance&.title.presence || default_brand_title
......@@ -25,7 +26,9 @@ module AppearancesHelper
end
def current_appearance
@appearance ||= Appearance.current
strong_memoize(:current_appearance) do
Appearance.current
end
end
def brand_header_logo
......
---
title: Memoize non-existent custom appearances
merge_request: 29957
author:
type: performance
......@@ -8,6 +8,22 @@ describe AppearancesHelper do
allow(helper).to receive(:current_user).and_return(user)
end
describe '.current_appearance' do
it 'memoizes empty appearance' do
expect(Appearance).to receive(:current).once
2.times { helper.current_appearance }
end
it 'memoizes custom appearance' do
create(:appearance)
expect(Appearance).to receive(:current).once.and_call_original
2.times { helper.current_appearance }
end
end
describe '#header_message' do
it 'returns nil when header message field is not set' do
create(:appearance)
......
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