Commit c19df237 authored by Thong Kuah's avatar Thong Kuah

Move disable_prepared_statements to Core

We use this method in initializer for Load Balancing
parent 7ce20dfb
......@@ -17,12 +17,6 @@ module EE
!Postgresql::ReplicationSlot.lag_too_great?
end
# Disables prepared statements for the current database connection.
def disable_prepared_statements
config = ::Gitlab::Database.config.merge(prepared_statements: false)
ActiveRecord::Base.establish_connection(config)
end
def geo_uncached_queries(&block)
raise 'No block given' unless block_given?
......
......@@ -60,28 +60,6 @@ RSpec.describe Gitlab::Database do
end
end
describe '.disable_prepared_statements' do
around do |example|
original_config = ::Gitlab::Database.config
example.run
ActiveRecord::Base.establish_connection(original_config)
end
it 'disables prepared statements' do
ActiveRecord::Base.establish_connection(::Gitlab::Database.config.merge(prepared_statements: true))
expect(ActiveRecord::Base.connection.prepared_statements).to eq(true)
expect(ActiveRecord::Base).to receive(:establish_connection)
.with(a_hash_including({ 'prepared_statements' => false })).and_call_original
described_class.disable_prepared_statements
expect(ActiveRecord::Base.connection.prepared_statements).to eq(false)
end
end
describe '.geo_uncached_queries' do
context 'when no block is given' do
it 'raises error' do
......
......@@ -89,6 +89,11 @@ module Gitlab
end
end
# Disables prepared statements for the current database connection.
def self.disable_prepared_statements
ActiveRecord::Base.establish_connection(config.merge(prepared_statements: false))
end
# @deprecated
def self.postgresql?
adapter_name.casecmp('postgresql') == 0
......
......@@ -65,6 +65,28 @@ RSpec.describe Gitlab::Database do
end
end
describe '.disable_prepared_statements' do
around do |example|
original_config = ::Gitlab::Database.config
example.run
ActiveRecord::Base.establish_connection(original_config)
end
it 'disables prepared statements' do
ActiveRecord::Base.establish_connection(::Gitlab::Database.config.merge(prepared_statements: true))
expect(ActiveRecord::Base.connection.prepared_statements).to eq(true)
expect(ActiveRecord::Base).to receive(:establish_connection)
.with(a_hash_including({ 'prepared_statements' => false })).and_call_original
described_class.disable_prepared_statements
expect(ActiveRecord::Base.connection.prepared_statements).to eq(false)
end
end
describe '.postgresql?' do
subject { described_class.postgresql? }
......
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