Merge branch '59162-fix-review-apps-initial-seeding' into 'master'
Fix race condition in ApplicationSettingImplementation.create_from_defaults Closes #59162 See merge request gitlab-org/gitlab-ce!26319
This commit is contained in:
commit
2bf4fefd12
|
@ -223,4 +223,11 @@ class ApplicationSetting < ApplicationRecord
|
|||
reset_memoized_terms
|
||||
end
|
||||
after_commit :expire_performance_bar_allowed_user_ids_cache, if: -> { previous_changes.key?('performance_bar_allowed_group_id') }
|
||||
|
||||
def self.create_from_defaults
|
||||
super
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# We already have an ApplicationSetting record, so just return it.
|
||||
current_without_cache
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
puts "Creating the default ApplicationSetting record.".color(:green)
|
||||
Gitlab::CurrentSettings.current_application_settings
|
||||
|
||||
# Details https://gitlab.com/gitlab-org/gitlab-ce/issues/46241
|
||||
puts "Enable hashed storage for every new projects.".color(:green)
|
||||
ApplicationSetting.current_without_cache.update!(hashed_storage_enabled: true)
|
||||
|
||||
print '.'
|
|
@ -1,8 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Enable hashed storage, in development mode, for all projects by default.
|
||||
Gitlab::Seeder.quiet do
|
||||
ApplicationSetting.create_from_defaults unless ApplicationSetting.current_without_cache
|
||||
ApplicationSetting.current_without_cache.update!(hashed_storage_enabled: true)
|
||||
print '.'
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# We want to enable hashed storage for every new project in development
|
||||
# Details https://gitlab.com/gitlab-org/gitlab-ce/issues/46241
|
||||
Gitlab::Seeder.quiet do
|
||||
ApplicationSetting.create_from_defaults unless ApplicationSetting.current_without_cache
|
||||
ApplicationSetting.current_without_cache.update!(hashed_storage_enabled: true)
|
||||
print '.'
|
||||
end
|
|
@ -1,2 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
puts "Creating the default ApplicationSetting record.".color(:green)
|
||||
Gitlab::CurrentSettings.current_application_settings
|
||||
|
|
|
@ -6,6 +6,7 @@ describe ApplicationSetting do
|
|||
let(:setting) { described_class.create_from_defaults }
|
||||
|
||||
it { include(CacheableAttributes) }
|
||||
it { include(ApplicationSettingImplementation) }
|
||||
it { expect(described_class.current_without_cache).to eq(described_class.last) }
|
||||
|
||||
it { expect(setting).to be_valid }
|
||||
|
@ -286,12 +287,10 @@ describe ApplicationSetting do
|
|||
end
|
||||
|
||||
context 'restrict creating duplicates' do
|
||||
before do
|
||||
described_class.create_from_defaults
|
||||
end
|
||||
let!(:current_settings) { described_class.create_from_defaults }
|
||||
|
||||
it 'raises an record creation violation if already created' do
|
||||
expect { described_class.create_from_defaults }.to raise_error(ActiveRecord::RecordNotUnique)
|
||||
it 'returns the current settings' do
|
||||
expect(described_class.create_from_defaults).to eq(current_settings)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue