Commit 088bd77d authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Rename use_replica to use_replica_if_possible

Issue https://gitlab.com/gitlab-org/gitlab/-/issues/322133
parent 3f079524
...@@ -53,7 +53,7 @@ class ApplicationRecord < ActiveRecord::Base ...@@ -53,7 +53,7 @@ class ApplicationRecord < ActiveRecord::Base
# Start a new transaction with a shorter-than-usual statement timeout. This is # Start a new transaction with a shorter-than-usual statement timeout. This is
# currently one third of the default 15-second timeout # currently one third of the default 15-second timeout
def self.with_fast_read_statement_timeout def self.with_fast_read_statement_timeout
::Gitlab::Database::LoadBalancing::Session.current.use_replica do ::Gitlab::Database::LoadBalancing::Session.current.use_replica_if_possible do
transaction(requires_new: true) do transaction(requires_new: true) do
connection.exec_query("SET LOCAL statement_timeout = 5000") connection.exec_query("SET LOCAL statement_timeout = 5000")
......
...@@ -18,7 +18,6 @@ module Gitlab ...@@ -18,7 +18,6 @@ module Gitlab
delete delete
delete_all delete_all
insert insert
transaction
update update
update_all update_all
).freeze ).freeze
......
...@@ -61,7 +61,7 @@ module Gitlab ...@@ -61,7 +61,7 @@ module Gitlab
# - If the queries are about to write # - If the queries are about to write
# - The current session already performed writes # - The current session already performed writes
# - It prefers to use primary, aka, use_primary or use_primary! were called # - It prefers to use primary, aka, use_primary or use_primary! were called
def use_replica(&blk) def use_replica_if_possible(&blk)
return yield if use_primary? || performed_write? return yield if use_primary? || performed_write?
begin begin
...@@ -74,7 +74,7 @@ module Gitlab ...@@ -74,7 +74,7 @@ module Gitlab
end end
def use_replica? def use_replica?
@use_replica && !use_primary? && !performed_write? @use_replica == true && !use_primary? && !performed_write?
end end
def write! def write!
......
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