mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Tweak truncate_tables
* Remove redundant `table_names.empty?` * Early return in `truncate_tables` since it is already deeply nested * Move `truncate_tables` out from between `exec_delete` and `exec_update`
This commit is contained in:
parent
d8d6bd5e63
commit
b707a448a3
2 changed files with 18 additions and 18 deletions
|
@ -142,23 +142,6 @@ module ActiveRecord
|
||||||
exec_query(sql, name, binds)
|
exec_query(sql, name, binds)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the truncate statement.
|
|
||||||
def truncate(table_name, name = nil)
|
|
||||||
execute(build_truncate_statements(table_name), name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def truncate_tables(*table_names) # :nodoc:
|
|
||||||
unless table_names.empty?
|
|
||||||
with_multi_statements do
|
|
||||||
disable_referential_integrity do
|
|
||||||
Array(build_truncate_statements(*table_names)).each do |sql|
|
|
||||||
execute_batch(sql, "Truncate Tables")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Executes update +sql+ statement in the context of this connection using
|
# Executes update +sql+ statement in the context of this connection using
|
||||||
# +binds+ as the bind substitutes. +name+ is logged along with
|
# +binds+ as the bind substitutes. +name+ is logged along with
|
||||||
# the executed +sql+ statement.
|
# the executed +sql+ statement.
|
||||||
|
@ -193,6 +176,23 @@ module ActiveRecord
|
||||||
exec_delete(sql, name, binds)
|
exec_delete(sql, name, binds)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Executes the truncate statement.
|
||||||
|
def truncate(table_name, name = nil)
|
||||||
|
execute(build_truncate_statements(table_name), name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def truncate_tables(*table_names) # :nodoc:
|
||||||
|
return if table_names.empty?
|
||||||
|
|
||||||
|
with_multi_statements do
|
||||||
|
disable_referential_integrity do
|
||||||
|
Array(build_truncate_statements(*table_names)).each do |sql|
|
||||||
|
execute_batch(sql, "Truncate Tables")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Runs the given block in a database transaction, and returns the result
|
# Runs the given block in a database transaction, and returns the result
|
||||||
# of the block.
|
# of the block.
|
||||||
#
|
#
|
||||||
|
|
|
@ -190,7 +190,7 @@ module ActiveRecord
|
||||||
ActiveRecord::Base.internal_metadata_table_name
|
ActiveRecord::Base.internal_metadata_table_name
|
||||||
]
|
]
|
||||||
|
|
||||||
ActiveRecord::Base.connection.truncate_tables(*table_names) unless table_names.empty?
|
ActiveRecord::Base.connection.truncate_tables(*table_names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private :truncate_tables
|
private :truncate_tables
|
||||||
|
|
Loading…
Reference in a new issue