1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove ignored_sql from SQLCounter by adding "TRANSACTION" to log name

This commit adds "TRANSACTION" to savepoint and commit, rollback statements
because none of savepoint statements were removed by #36153 since they are not "SCHEMA" statements.

Although, only savepoint statements can be labeled as "TRANSACTION"
I think all of transaction related method should add this label.

Follow up #36153
This commit is contained in:
Yasuo Honda 2019-05-07 04:29:53 +00:00
parent cecbc2340a
commit 6a32e8aa72
6 changed files with 15 additions and 23 deletions

View file

@ -8,15 +8,15 @@ module ActiveRecord
end end
def create_savepoint(name = current_savepoint_name) def create_savepoint(name = current_savepoint_name)
execute("SAVEPOINT #{name}") execute("SAVEPOINT #{name}", "TRANSACTION")
end end
def exec_rollback_to_savepoint(name = current_savepoint_name) def exec_rollback_to_savepoint(name = current_savepoint_name)
execute("ROLLBACK TO SAVEPOINT #{name}") execute("ROLLBACK TO SAVEPOINT #{name}", "TRANSACTION")
end end
def release_savepoint(name = current_savepoint_name) def release_savepoint(name = current_savepoint_name)
execute("RELEASE SAVEPOINT #{name}") execute("RELEASE SAVEPOINT #{name}", "TRANSACTION")
end end
end end
end end

View file

@ -204,7 +204,7 @@ module ActiveRecord
end end
def begin_db_transaction def begin_db_transaction
execute "BEGIN" execute("BEGIN", "TRANSACTION")
end end
def begin_isolated_db_transaction(isolation) def begin_isolated_db_transaction(isolation)
@ -213,11 +213,11 @@ module ActiveRecord
end end
def commit_db_transaction #:nodoc: def commit_db_transaction #:nodoc:
execute "COMMIT" execute("COMMIT", "TRANSACTION")
end end
def exec_rollback_db_transaction #:nodoc: def exec_rollback_db_transaction #:nodoc:
execute "ROLLBACK" execute("ROLLBACK", "TRANSACTION")
end end
def empty_insert_statement_value(primary_key = nil) def empty_insert_statement_value(primary_key = nil)

View file

@ -145,7 +145,7 @@ module ActiveRecord
# Begins a transaction. # Begins a transaction.
def begin_db_transaction def begin_db_transaction
execute "BEGIN" execute("BEGIN", "TRANSACTION")
end end
def begin_isolated_db_transaction(isolation) def begin_isolated_db_transaction(isolation)
@ -155,12 +155,12 @@ module ActiveRecord
# Commits a transaction. # Commits a transaction.
def commit_db_transaction def commit_db_transaction
execute "COMMIT" execute("COMMIT", "TRANSACTION")
end end
# Aborts a transaction. # Aborts a transaction.
def exec_rollback_db_transaction def exec_rollback_db_transaction
execute "ROLLBACK" execute("ROLLBACK", "TRANSACTION")
end end
private private

View file

@ -68,15 +68,15 @@ module ActiveRecord
alias :exec_update :exec_delete alias :exec_update :exec_delete
def begin_db_transaction #:nodoc: def begin_db_transaction #:nodoc:
log("begin transaction", nil) { @connection.transaction } log("begin transaction", "TRANSACTION") { @connection.transaction }
end end
def commit_db_transaction #:nodoc: def commit_db_transaction #:nodoc:
log("commit transaction", nil) { @connection.commit } log("commit transaction", "TRANSACTION") { @connection.commit }
end end
def exec_rollback_db_transaction #:nodoc: def exec_rollback_db_transaction #:nodoc:
log("rollback transaction", nil) { @connection.rollback } log("rollback transaction", "TRANSACTION") { @connection.rollback }
end end

View file

@ -13,7 +13,7 @@ class PostgreSQLReferentialIntegrityTest < ActiveRecord::PostgreSQLTestCase
end end
module MissingSuperuserPrivileges module MissingSuperuserPrivileges
def execute(sql) def execute(sql, name = nil)
if IS_REFERENTIAL_INTEGRITY_SQL.call(sql) if IS_REFERENTIAL_INTEGRITY_SQL.call(sql)
super "BROKEN;" rescue nil # put transaction in broken state super "BROKEN;" rescue nil # put transaction in broken state
raise ActiveRecord::StatementInvalid, "PG::InsufficientPrivilege" raise ActiveRecord::StatementInvalid, "PG::InsufficientPrivilege"
@ -24,7 +24,7 @@ class PostgreSQLReferentialIntegrityTest < ActiveRecord::PostgreSQLTestCase
end end
module ProgrammerMistake module ProgrammerMistake
def execute(sql) def execute(sql, name = nil)
if IS_REFERENTIAL_INTEGRITY_SQL.call(sql) if IS_REFERENTIAL_INTEGRITY_SQL.call(sql)
raise ArgumentError, "something is not right." raise ArgumentError, "something is not right."
else else

View file

@ -107,20 +107,12 @@ module ActiveRecord
clear_log clear_log
self.ignored_sql = [/^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/]
attr_reader :ignore
def initialize(ignore = Regexp.union(self.class.ignored_sql))
@ignore = ignore
end
def call(name, start, finish, message_id, values) def call(name, start, finish, message_id, values)
return if values[:cached] return if values[:cached]
sql = values[:sql] sql = values[:sql]
self.class.log_all << sql self.class.log_all << sql
self.class.log << sql unless values[:name] == "SCHEMA" || ignore.match?(sql) self.class.log << sql unless ["SCHEMA", "TRANSACTION"].include? values[:name]
end end
end end