Commit 5fbd0ff4 authored by Stan Hu's avatar Stan Hu

Memoize non-existent custom appearances

This saves about 5 SQL calls per page if no custom appearance is
specified.
parent f89a33c9
......@@ -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