Commit 3f079524 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Force with_fast_statement_timeout to use replicas

parent e1b019bf
......@@ -52,11 +52,13 @@ class ApplicationRecord < ActiveRecord::Base
# Start a new transaction with a shorter-than-usual statement timeout. This is
# currently one third of the default 15-second timeout
def self.with_fast_statement_timeout
transaction(requires_new: true) do
connection.exec_query("SET LOCAL statement_timeout = 5000")
def self.with_fast_read_statement_timeout
::Gitlab::Database::LoadBalancing::Session.current.use_replica do
transaction(requires_new: true) do
connection.exec_query("SET LOCAL statement_timeout = 5000")
yield
yield
end
end
end
......
......@@ -78,7 +78,7 @@ module Gitlab
# to perform the calculation more efficiently. Until then, use a shorter
# timeout and return -1 as a sentinel value if it is triggered
begin
ApplicationRecord.with_fast_statement_timeout do
ApplicationRecord.with_fast_read_statement_timeout do
finder.count_by_state
end
rescue ActiveRecord::QueryCanceled => err
......
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