Skip to content

Commit

Permalink
Merge pull request #44531 from matthewd/rm-mark-written
Browse files Browse the repository at this point in the history
Remove mark_transaction_written_if_write
  • Loading branch information
matthewd committed Feb 24, 2022
2 parents d49f956 + b95354e commit 199fe99
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 18 deletions.
Expand Up @@ -325,13 +325,6 @@ def transaction(requires_new: nil, isolation: nil, joinable: true, &block)
:commit_transaction, :rollback_transaction, :materialize_transactions,
:disable_lazy_transactions!, :enable_lazy_transactions!, to: :transaction_manager

def mark_transaction_written_if_write(sql) # :nodoc:
transaction = current_transaction
if transaction.open?
transaction.written ||= write_query?(sql)
end
end

def transaction_open?
current_transaction.open?
end
Expand Down
Expand Up @@ -84,7 +84,6 @@ def add_record(record, _ = true); end

class Transaction # :nodoc:
attr_reader :connection, :state, :savepoint_name, :isolation_level
attr_accessor :written

def initialize(connection, isolation: nil, joinable: true, run_commit_callbacks: false)
@connection = connection
Expand Down Expand Up @@ -338,7 +337,7 @@ def within_new_transaction(isolation: nil, joinable: true)
# @connection still holds an open or invalid transaction, so we must not
# put it back in the pool for reuse.
@connection.throw_away! unless transaction.state.rolledback?
elsif Thread.current.status == "aborting" || (!completed && transaction.written)
elsif Thread.current.status == "aborting" || !completed
# The transaction is still open but the block returned earlier.
#
# The block could return early because of a timeout or because the thread is aborting,
Expand Down
Expand Up @@ -636,7 +636,6 @@ def extended_type_map_key

def raw_execute(sql, name, async: false)
materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name, async: async) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Expand Down
Expand Up @@ -168,7 +168,6 @@ def exec_stmt_and_free(sql, name, binds, cache_stmt: false, async: false)
check_if_write_query(sql)

materialize_transactions
mark_transaction_written_if_write(sql)

# make sure we carry over any changes to ActiveRecord.default_timezone that have been
# made since we established the connection
Expand Down
Expand Up @@ -12,7 +12,6 @@ def explain(arel, binds = [])
# Queries the database and returns the results in an Array-like object
def query(sql, name = nil) # :nodoc:
materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Expand Down Expand Up @@ -41,7 +40,6 @@ def execute(sql, name = nil)
check_if_write_query(sql)

materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Expand Down
Expand Up @@ -757,7 +757,6 @@ def execute_and_clear(sql, name, binds, prepare: false, async: false)

def exec_no_cache(sql, name, binds, async: false)
materialize_transactions
mark_transaction_written_if_write(sql)

# make sure we carry over any changes to ActiveRecord.default_timezone that have been
# made since we established the connection
Expand All @@ -773,7 +772,6 @@ def exec_no_cache(sql, name, binds, async: false)

def exec_cache(sql, name, binds, async: false)
materialize_transactions
mark_transaction_written_if_write(sql)
update_typemap_for_default_timezone

stmt_key = prepare_statement(sql, binds)
Expand Down
Expand Up @@ -25,7 +25,6 @@ def execute(sql, name = nil) # :nodoc:
check_if_write_query(sql)

materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Expand All @@ -39,7 +38,6 @@ def exec_query(sql, name = nil, binds = [], prepare: false, async: false) # :nod
check_if_write_query(sql)

materialize_transactions
mark_transaction_written_if_write(sql)

type_casted_binds = type_casted_binds(binds)

Expand Down Expand Up @@ -123,7 +121,6 @@ def execute_batch(statements, name = nil)
check_if_write_query(sql)

materialize_transactions
mark_transaction_written_if_write(sql)

log(sql, name) do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Expand Down

0 comments on commit 199fe99

Please sign in to comment.