Commit 39e8ac1a authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-gitlab-edition-memoize' into 'master'

Memoize GitlabEdition.ee? and GitlabEdition.jh?

See merge request gitlab-org/gitlab!80600
parents e6addfb6 b304c357
...@@ -18,7 +18,11 @@ module GitlabEdition ...@@ -18,7 +18,11 @@ module GitlabEdition
end end
def self.ee? def self.ee?
@is_ee ||= # To reduce dependencies in QA image we are not using
# `Gitlab::Utils::StrongMemoize` but reimplementing its functionality.
return @is_ee if defined?(@is_ee)
@is_ee =
# We use this method when the Rails environment is not loaded. This # We use this method when the Rails environment is not loaded. This
# means that checking the presence of the License class could result in # means that checking the presence of the License class could result in
# this method returning `false`, even for an EE installation. # this method returning `false`, even for an EE installation.
...@@ -34,7 +38,9 @@ module GitlabEdition ...@@ -34,7 +38,9 @@ module GitlabEdition
end end
def self.jh? def self.jh?
@is_jh ||= return @is_jh if defined?(@is_jh)
@is_jh =
ee? && ee? &&
root.join('jh').exist? && root.join('jh').exist? &&
!%w[true 1].include?(ENV['EE_ONLY'].to_s) !%w[true 1].include?(ENV['EE_ONLY'].to_s)
......
...@@ -3,18 +3,22 @@ ...@@ -3,18 +3,22 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe GitlabEdition do RSpec.describe GitlabEdition do
def remove_instance_variable(ivar)
described_class.remove_instance_variable(ivar) if described_class.instance_variable_defined?(ivar)
end
before do before do
# Make sure the ENV is clean # Make sure the ENV is clean
stub_env('FOSS_ONLY', nil) stub_env('FOSS_ONLY', nil)
stub_env('EE_ONLY', nil) stub_env('EE_ONLY', nil)
described_class.instance_variable_set(:@is_ee, nil) remove_instance_variable(:@is_ee)
described_class.instance_variable_set(:@is_jh, nil) remove_instance_variable(:@is_jh)
end end
after do after do
described_class.instance_variable_set(:@is_ee, nil) remove_instance_variable(:@is_ee)
described_class.instance_variable_set(:@is_jh, nil) remove_instance_variable(:@is_jh)
end end
describe '.root' do describe '.root' do
...@@ -51,7 +55,7 @@ RSpec.describe GitlabEdition do ...@@ -51,7 +55,7 @@ RSpec.describe GitlabEdition do
allow(described_class).to receive(:ee?).and_return(false) allow(described_class).to receive(:ee?).and_return(false)
end end
it 'returns the exyensions according to the current edition' do it 'returns the extensions according to the current edition' do
expect(described_class.extensions).to be_empty expect(described_class.extensions).to be_empty
end end
end end
...@@ -77,7 +81,7 @@ RSpec.describe GitlabEdition do ...@@ -77,7 +81,7 @@ RSpec.describe GitlabEdition do
end end
describe '.ee?' do describe '.ee?' do
context 'for EE' do context 'when EE' do
before do before do
stub_path('ee/app/models/license.rb', exist?: true) stub_path('ee/app/models/license.rb', exist?: true)
end end
...@@ -109,7 +113,7 @@ RSpec.describe GitlabEdition do ...@@ -109,7 +113,7 @@ RSpec.describe GitlabEdition do
end end
end end
context 'for CE' do context 'when CE' do
before do before do
stub_path('ee/app/models/license.rb', exist?: false) stub_path('ee/app/models/license.rb', exist?: false)
end end
...@@ -121,12 +125,9 @@ RSpec.describe GitlabEdition do ...@@ -121,12 +125,9 @@ RSpec.describe GitlabEdition do
end end
describe '.jh?' do describe '.jh?' do
context 'for JH' do context 'when JH' do
before do before do
stub_path( stub_path('ee/app/models/license.rb', 'jh', exist?: true)
'ee/app/models/license.rb',
'jh',
exist?: true)
end end
context 'when using default FOSS_ONLY and EE_ONLY' do context 'when using default FOSS_ONLY and EE_ONLY' do
......
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