aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-18 00:21:40 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-03-18 00:21:40 +0900
commitb707a448a34345cd0a6609b8bd57874f1325a96c (patch)
tree7cf62618b531886fe8caa9c4fac3d691684b41fe
parentd8d6bd5e63a9a4a6c06a4dde3c7137ee2be105fd (diff)
downloadrails-b707a448a34345cd0a6609b8bd57874f1325a96c.tar.gz
rails-b707a448a34345cd0a6609b8bd57874f1325a96c.tar.bz2
rails-b707a448a34345cd0a6609b8bd57874f1325a96c.zip
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`
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb34
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
2 files changed, 18 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index 6ea85a691b..6aacbe5f88 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -142,23 +142,6 @@ module ActiveRecord
exec_query(sql, name, binds)
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
# +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
@@ -193,6 +176,23 @@ module ActiveRecord
exec_delete(sql, name, binds)
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
# of the block.
#
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index f18990cc5b..155d2b0b98 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -190,7 +190,7 @@ module ActiveRecord
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
private :truncate_tables