Commit 176c82e9 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '328497-disable-lb-query-cache-in-non-request-contexts' into 'master'

Disable query cache when outside Rails executor

See merge request gitlab-org/gitlab!73814
parents cc5fd26d 23152fd9
...@@ -266,7 +266,10 @@ module Gitlab ...@@ -266,7 +266,10 @@ module Gitlab
private private
def ensure_caching! def ensure_caching!
host.enable_query_cache! unless host.query_cache_enabled return unless Rails.application.executor.active?
return if host.query_cache_enabled
host.enable_query_cache!
end end
def request_cache def request_cache
......
...@@ -89,6 +89,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do ...@@ -89,6 +89,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do
host = double(:host) host = double(:host)
allow(lb).to receive(:host).and_return(host) allow(lb).to receive(:host).and_return(host)
allow(Rails.application.executor).to receive(:active?).and_return(true)
allow(host).to receive(:query_cache_enabled).and_return(false) allow(host).to receive(:query_cache_enabled).and_return(false)
allow(host).to receive(:connection).and_return(connection) allow(host).to receive(:connection).and_return(connection)
...@@ -97,6 +98,20 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do ...@@ -97,6 +98,20 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do
lb.read { 10 } lb.read { 10 }
end end
it 'does not enable query cache when outside Rails executor context' do
connection = double(:connection)
host = double(:host)
allow(lb).to receive(:host).and_return(host)
allow(Rails.application.executor).to receive(:active?).and_return(false)
allow(host).to receive(:query_cache_enabled).and_return(false)
allow(host).to receive(:connection).and_return(connection)
expect(host).not_to receive(:enable_query_cache!)
lb.read { 10 }
end
it 'marks hosts that are offline' do it 'marks hosts that are offline' do
allow(lb).to receive(:connection_error?).and_return(true) allow(lb).to receive(:connection_error?).and_return(true)
......
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