summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-06-24 04:55:43 +0000
committerThong Kuah <tkuah@gitlab.com>2019-06-24 04:55:43 +0000
commit833013ba4a855d62cfbc691c3ba95e06876a1634 (patch)
treee4c379de83c9a3b61e0c087d90247b9e58847851
parente740580dcf8e5b09b5baa0b2763edafa0b289eae (diff)
parent5fbd0ff460ec982cce570266f53176a8cf071326 (diff)
downloadgitlab-ce-833013ba4a855d62cfbc691c3ba95e06876a1634.tar.gz
Merge branch 'sh-strong-memoize-appearances' into 'master'
Memoize non-existent custom appearances See merge request gitlab-org/gitlab-ce!29957
-rw-r--r--app/helpers/appearances_helper.rb5
-rw-r--r--changelogs/unreleased/sh-strong-memoize-appearances.yml5
-rw-r--r--spec/helpers/appearances_helper_spec.rb16
3 files changed, 25 insertions, 1 deletions
diff --git a/app/helpers/appearances_helper.rb b/app/helpers/appearances_helper.rb
index c0db9910143..6b43d52c775 100644
--- a/app/helpers/appearances_helper.rb
+++ b/app/helpers/appearances_helper.rb
@@ -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
diff --git a/changelogs/unreleased/sh-strong-memoize-appearances.yml b/changelogs/unreleased/sh-strong-memoize-appearances.yml
new file mode 100644
index 00000000000..dc4fe1c4d8e
--- /dev/null
+++ b/changelogs/unreleased/sh-strong-memoize-appearances.yml
@@ -0,0 +1,5 @@
+---
+title: Memoize non-existent custom appearances
+merge_request: 29957
+author:
+type: performance
diff --git a/spec/helpers/appearances_helper_spec.rb b/spec/helpers/appearances_helper_spec.rb
index a3511e078ce..ed3e31b3c53 100644
--- a/spec/helpers/appearances_helper_spec.rb
+++ b/spec/helpers/appearances_helper_spec.rb
@@ -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)